-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34e133b
commit 47e3f32
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...c/main/java/io/quarkus/opentelemetry/runtime/config/build/EndUserSpanProcessorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.opentelemetry.runtime.config.build; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.smallrye.config.WithDefault; | ||
|
||
/** | ||
* Tracing build time configuration | ||
*/ | ||
@ConfigGroup | ||
public interface EndUserSpanProcessorConfig { | ||
|
||
/** | ||
* Enable tracing with OpenTelemetry. | ||
* <p> | ||
* This property is not available in the Open Telemetry SDK. It's Quarkus specific. | ||
* <p> | ||
* Support for tracing will be enabled if OpenTelemetry support is enabled | ||
* and either this value is true, or this value is unset. | ||
*/ | ||
@WithDefault("false") | ||
Optional<Boolean> enabled(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...me/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/EndUserSpanProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.quarkus.opentelemetry.runtime.exporter.otlp; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.trace.ReadWriteSpan; | ||
import io.opentelemetry.sdk.trace.ReadableSpan; | ||
import io.opentelemetry.sdk.trace.SpanProcessor; | ||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.context.control.ActivateRequestContext; | ||
import jakarta.inject.Inject; | ||
import org.eclipse.microprofile.context.ManagedExecutor; | ||
|
||
@ApplicationScoped | ||
public class EndUserSpanProcessor implements SpanProcessor { | ||
|
||
@Inject | ||
protected SecurityIdentity securityIdentity; | ||
|
||
@Inject | ||
protected ManagedExecutor managedExecutor; | ||
|
||
@Override | ||
@ActivateRequestContext | ||
public void onStart(Context parentContext, ReadWriteSpan span) { | ||
managedExecutor.execute( | ||
() -> span.setAllAttributes( | ||
securityIdentity.isAnonymous() | ||
? Attributes.empty() | ||
: Attributes.of( | ||
SemanticAttributes.ENDUSER_ID, | ||
securityIdentity.getPrincipal().getName(), | ||
SemanticAttributes.ENDUSER_ROLE, | ||
securityIdentity.getRoles().toString() | ||
) | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean isStartRequired() { | ||
return Boolean.TRUE; | ||
} | ||
|
||
@Override | ||
public void onEnd(ReadableSpan span) { | ||
} | ||
|
||
@Override | ||
public boolean isEndRequired() { | ||
return Boolean.FALSE; | ||
} | ||
|
||
} |