Skip to content

feat: Metrics tracer addAttribute map overload #3202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ public void addAttributes(String key, String value) {
attributes.put(key, value);
};

/**
* Add attributes that will be attached to all metrics. This is expected to be called by
* handwritten client teams to add additional attributes that are not supposed be collected by
* Gax.
*/
public void addAttributes(Map<String, String> attributes) {
this.attributes.putAll(attributes);
};

@VisibleForTesting
Map<String, String> getAttributes() {
return attributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.google.api.gax.rpc.StatusCode.Code;
import com.google.api.gax.rpc.testing.FakeStatusCode;
import com.google.common.collect.ImmutableMap;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -228,6 +229,16 @@ void testAddAttributes_recordsAttributes() {
assertThat(metricsTracer.getAttributes().get("FakeTableId")).isEqualTo("12345");
}

@Test
void testAddAttributes_recordsAttributesWithMap() {
Map<String, String> attributes = new HashMap<>();
attributes.put("FakeTableId", "12345");
attributes.put("FakeInstanceId", "67890");
metricsTracer.addAttributes(attributes);
assertThat(metricsTracer.getAttributes().get("FakeTableId")).isEqualTo("12345");
assertThat(metricsTracer.getAttributes().get("FakeInstanceId")).isEqualTo("67890");
}

@Test
void testExtractStatus_errorConversion_apiExceptions() {
ApiException error =
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy