-
Notifications
You must be signed in to change notification settings - Fork 17
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
Observation otel IT #297
base: main
Are you sure you want to change the base?
Observation otel IT #297
Changes from all commits
2e52ca7
dcefe24
f8ccc20
7d4b75f
e6e6b3c
664a2d9
198230b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_ADDR; | ||
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_PORT; | ||
import static io.opentelemetry.semconv.SemanticAttributes.PEER_SERVICE; | ||
import static io.smallrye.opentelemetry.instrumentation.observation.handler.HandlerUtil.HIGH_CARD_ATTRIBUTES; | ||
import static io.smallrye.opentelemetry.instrumentation.observation.handler.HandlerUtil.LOW_CARD_ATTRIBUTES; | ||
|
||
import java.net.URI; | ||
import java.util.logging.Logger; | ||
|
@@ -108,16 +110,37 @@ protected Span getParentSpan(T context) { | |
return null; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
protected void tagSpan(T context, Span span) { | ||
final Attributes highCardAttributes = context.get(HIGH_CARD_ATTRIBUTES); | ||
setOtelAttributes(span, highCardAttributes); | ||
|
||
final Attributes lowCardAttributes = context.get(LOW_CARD_ATTRIBUTES); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these always set, no matter what? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The low cardinality ones, yes. |
||
setOtelAttributes(span, lowCardAttributes); | ||
|
||
for (KeyValue keyValue : context.getAllKeyValues()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it contain keys from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but originally stored in 2 different structures. |
||
if (!keyValue.getKey().equalsIgnoreCase("ERROR")) { | ||
span.setAttribute(keyValue.getKey(), keyValue.getValue()); | ||
|
||
} else { | ||
span.recordException(new RuntimeException(keyValue.getValue())); | ||
} | ||
} | ||
} | ||
|
||
private void setOtelAttributes(Span span, Attributes contextAttributes) { | ||
if (contextAttributes != null) { | ||
contextAttributes.forEach((key, value) -> { | ||
// FIXME this is a bit of a hack because KeyValue only allows String values | ||
if (key.getKey().equalsIgnoreCase("ERROR")) { | ||
span.recordException(new RuntimeException(value.toString())); | ||
} else { | ||
span.setAttribute((AttributeKey<Object>) key, value); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
protected SpanBuilder remoteSpanBuilder(Kind kind, | ||
String remoteServiceName, | ||
String remoteServiceAddress, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.smallrye.opentelemetry.instrumentation.observation.handler; | ||
|
||
public class HandlerUtil { | ||
public static final String LOW_CARD_ATTRIBUTES = "low_card_attributes"; | ||
public static final String HIGH_CARD_ATTRIBUTES = "high_card_attributes"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ public String get(C carrier, String key) { | |
return getter.get(carrier, key); | ||
} | ||
}); | ||
// extracted.makeCurrent(); // this actually fixes the baggage test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically, if you uncomment, baggage propagation will be fixed, is there for reference... We can remove these comments but I will need to document these things somewhere, maybe on a README... What do you think? |
||
return tracer.spanBuilder("receiver").setParent(extracted);// FIXME the name needs to be set | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.smallrye.opentelemetry.instrumentation.observation.handler; | ||
|
||
import io.micrometer.core.instrument.observation.MeterObservationHandler; | ||
import io.micrometer.observation.Observation; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.Tracer; | ||
import io.opentelemetry.context.Scope; | ||
import io.smallrye.opentelemetry.instrumentation.observation.context.TracingObservationContext; | ||
|
||
public class TracingAwareMeterObservationHandler<T extends Observation.Context> implements MeterObservationHandler<T> { | ||
|
||
private final MeterObservationHandler<T> delegate; | ||
|
||
private final Tracer tracer; | ||
|
||
/** | ||
* Creates a new instance of {@link TracingAwareMeterObservationHandler}. | ||
* | ||
* @param delegate a {@link MeterObservationHandler} delegate | ||
* @param tracer tracer | ||
*/ | ||
public TracingAwareMeterObservationHandler(MeterObservationHandler<T> delegate, Tracer tracer) { | ||
this.delegate = delegate; | ||
this.tracer = tracer; | ||
} | ||
|
||
@Override | ||
public void onStart(T context) { | ||
this.delegate.onStart(context); | ||
} | ||
|
||
@Override | ||
public void onError(T context) { | ||
this.delegate.onError(context); | ||
} | ||
|
||
@Override | ||
public void onEvent(Observation.Event event, T context) { | ||
this.delegate.onEvent(event, context); | ||
} | ||
|
||
@Override | ||
public void onScopeOpened(T context) { | ||
this.delegate.onScopeOpened(context); | ||
} | ||
|
||
@Override | ||
public void onScopeClosed(T context) { | ||
this.delegate.onScopeClosed(context); | ||
} | ||
|
||
@Override | ||
public void onStop(T context) { | ||
TracingObservationContext tracingContext = context | ||
.getRequired(TracingObservationContext.class); | ||
Span currentSpan = tracingContext.getSpan(); | ||
if (currentSpan != null) { | ||
try (Scope scope = currentSpan.makeCurrent()) { | ||
this.delegate.onStop(context); | ||
} | ||
} else { | ||
this.delegate.onStop(context); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean supportsContext(Observation.Context context) { | ||
return this.delegate.supportsContext(context); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
otel.logs.exporter=none | ||
#otel.logs.exporter=none | ||
otel.metric.export.interval=1000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.smallrye.opentelemetry</groupId> | ||
<artifactId>smallrye-opentelemetry-parent</artifactId> | ||
<version>2.8.2-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>smallrye-opentelemetry-rest-observation</artifactId> | ||
<name>SmallRye OpenTelemetry: REST Observation</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.smallrye.opentelemetry</groupId> | ||
<artifactId>smallrye-opentelemetry-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.smallrye.opentelemetry</groupId> | ||
<artifactId>smallrye-opentelemetry-micrometer-otel-bridge</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.smallrye.opentelemetry</groupId> | ||
<artifactId>smallrye-opentelemetry-observation-otel-bridge</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>jakarta.enterprise</groupId> | ||
<artifactId>jakarta.enterprise.cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>jakarta.ws.rs</groupId> | ||
<artifactId>jakarta.ws.rs-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.opentelemetry.semconv</groupId> | ||
<artifactId>opentelemetry-semconv</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means it doesn't provide baggage propagation through the Observation API. The OTel API can be used instead...
Implementing this is not trivial and the comment explains the possible approach.