bvolpato commented on code in PR #27078: URL: https://github.com/apache/beam/pull/27078#discussion_r1227470717
########## sdks/java/harness/src/main/java/org/apache/beam/fn/harness/logging/QuotaEvent.java: ########## @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.fn.harness.logging; + +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; +import org.slf4j.MDC; + +/** + * Adds MDC key:value pairs for a quota event. The contents of the MDC are added to each log entry. + * + * <p>Suggested usage: try (QuotaEventCloseable qec = new + * QuotaEvent.Builder().withOperation(op).withFullResourceName(name).create()) { LOG.info(...); } + */ +public class QuotaEvent { + public static class QuotaEventCloseable implements AutoCloseable { + public QuotaEventCloseable(Map<String, String> data) { + this.data = data; + } + + @Override + public void close() { + if (!enabled) { + return; + } + for (String key : data.keySet()) { + MDC.remove(key); + } Review Comment: Shouldn't we apply back what was in the stack instead of removing? Or we have no expectations for MDCs to be re-entrant? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
