Skip to content
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
2 changes: 1 addition & 1 deletion examples/distro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The `InstrumenterCustomizerProvider` extension point allows you to customize ins
- Add custom attributes and metrics to existing instrumentations
- Customize context
- Transform span names to match your naming conventions
- Apply customizations conditionally based on instrumentation name
- Apply customizations conditionally based on instrumentation name or type (HTTP client, HTTP server, DB client, etc.)

### I don't want this span at all

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* </ul>
*
* <p>The customizer will be automatically applied to instrumenters that match the specified
* instrumentation name and span kind.
* instrumentation name or type.
*
* @see InstrumenterCustomizerProvider
* @see InstrumenterCustomizer
Expand All @@ -48,6 +48,10 @@ public void customize(InstrumenterCustomizer customizer) {
if (isHttpServerInstrumentation(instrumentationName)) {
customizeHttpServer(customizer);
}

if (customizer.hasType(InstrumenterCustomizer.InstrumentationType.HTTP_CLIENT)) {
customizeHttpClient(customizer);
}
}

private boolean isHttpServerInstrumentation(String instrumentationName) {
Expand All @@ -66,6 +70,31 @@ private void customizeHttpServer(InstrumenterCustomizer customizer) {
unused -> (SpanNameExtractor<Object>) object -> "CustomHTTP/" + object.toString());
}

private void customizeHttpClient(InstrumenterCustomizer customizer) {
// Simple customization for HTTP client instrumentations
customizer.addAttributesExtractor(new DemoHttpClientAttributesExtractor());
}

/** Custom attributes extractor for HTTP client instrumentations. */
private static class DemoHttpClientAttributesExtractor
implements AttributesExtractor<Object, Object> {
private static final AttributeKey<String> CLIENT_ATTR =
AttributeKey.stringKey("demo.client.type");

@Override
public void onStart(AttributesBuilder attributes, Context context, Object request) {
attributes.put(CLIENT_ATTR, "demo-http-client");
}

@Override
public void onEnd(
AttributesBuilder attributes,
Context context,
Object request,
Object response,
Throwable error) {}
}

/** Custom attributes extractor that adds demo-specific attributes. */
private static class DemoAttributesExtractor implements AttributesExtractor<Object, Object> {
private static final AttributeKey<String> CUSTOM_ATTR = AttributeKey.stringKey("demo.custom");
Expand Down
2 changes: 1 addition & 1 deletion examples/extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The `InstrumenterCustomizerProvider` extension point allows you to customize ins
- Add custom attributes and metrics to existing instrumentations
- Customize context
- Transform span names to match your naming conventions
- Apply customizations conditionally based on instrumentation name
- Apply customizations conditionally based on instrumentation name or type (HTTP client, HTTP server, DB client, etc.)

### "I don't want this span at all"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
* <p>This customizer adds:
*
* <ul>
* <li>Custom attributes to HTTP server spans
* <li>Custom attributes to HTTP server spans (based on instrumentation name)
* <li>Custom attributes to HTTP client spans (based on instrumentation type)
* <li>Custom metrics for HTTP operations
* <li>Request correlation IDs via context customization
* <li>Custom span name transformation
* </ul>
*
* <p>The customizer will be automatically applied to instrumenters that match the specified
* instrumentation name and span kind.
* instrumentation name or type.
*
* @see InstrumenterCustomizerProvider
* @see InstrumenterCustomizer
Expand All @@ -50,6 +51,10 @@ public void customize(InstrumenterCustomizer customizer) {
if (isHttpServerInstrumentation(instrumentationName)) {
customizeHttpServer(customizer);
}

if (customizer.hasType(InstrumenterCustomizer.InstrumentationType.HTTP_CLIENT)) {
customizeHttpClient(customizer);
}
}

private boolean isHttpServerInstrumentation(String instrumentationName) {
Expand All @@ -68,6 +73,31 @@ private void customizeHttpServer(InstrumenterCustomizer customizer) {
unused -> (SpanNameExtractor<Object>) object -> "CustomHTTP/" + object.toString());
}

private void customizeHttpClient(InstrumenterCustomizer customizer) {
// Simple customization for HTTP client instrumentations
customizer.addAttributesExtractor(new DemoHttpClientAttributesExtractor());
}

/** Custom attributes extractor for HTTP client instrumentations. */
private static class DemoHttpClientAttributesExtractor
implements AttributesExtractor<Object, Object> {
private static final AttributeKey<String> CLIENT_ATTR =
AttributeKey.stringKey("demo.client.type");

@Override
public void onStart(AttributesBuilder attributes, Context context, Object request) {
attributes.put(CLIENT_ATTR, "demo-http-client");
}

@Override
public void onEnd(
AttributesBuilder attributes,
Context context,
Object request,
Object response,
Throwable error) {}
}

/** Custom attributes extractor that adds demo-specific attributes. */
private static class DemoAttributesExtractor implements AttributesExtractor<Object, Object> {
private static final AttributeKey<String> CUSTOM_ATTR = AttributeKey.stringKey("demo.custom");
Expand Down
Loading