Skip to content
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

Move capturing enduser.id attribute behind a flag #9751

Merged
merged 3 commits into from
Oct 31, 2023
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 instrumentation/servlet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Settings

| System property | Type | Default | Description |
| ---------------------------------------------------------------------- | ------- | ------- | --------------------------------------------------- |
|------------------------------------------------------------------------| ------- | ------- |-----------------------------------------------------|
| `otel.instrumentation.servlet.experimental-span-attributes` | Boolean | `false` | Enable the capture of experimental span attributes. |
| `otel.instrumentation.servlet.experimental.capture-request-parameters` | List | Empty | Request parameters to be captured (experimental). |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRoute;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge;
import io.opentelemetry.javaagent.bootstrap.servlet.MappingResolver;
import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath;
Expand Down Expand Up @@ -135,6 +136,10 @@ private void captureRequestParameters(Span serverSpan, REQUEST request) {
* created by servlet instrumentation we call this method on exit from the last servlet or filter.
*/
private void captureEnduserId(Span serverSpan, REQUEST request) {
if (!CommonConfig.get().shouldCaptureEnduser()) {
return;
}

Principal principal = accessor.getRequestUserPrincipal(request);
if (principal != null) {
String name = principal.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig;
import io.opentelemetry.semconv.SemanticAttributes;
import java.security.Principal;
Expand Down Expand Up @@ -43,11 +44,13 @@ public void onEnd(
ServletRequestContext<REQUEST> requestContext,
@Nullable ServletResponseContext<RESPONSE> responseContext,
@Nullable Throwable error) {
Principal principal = accessor.getRequestUserPrincipal(requestContext.request());
if (principal != null) {
String name = principal.getName();
if (name != null) {
attributes.put(SemanticAttributes.ENDUSER_ID, name);
if (CommonConfig.get().shouldCaptureEnduser()) {
Principal principal = accessor.getRequestUserPrincipal(requestContext.request());
if (principal != null) {
String name = principal.getName();
if (name != null) {
attributes.put(SemanticAttributes.ENDUSER_ID, name);
}
}
}
if (!CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static CommonConfig get() {
private final boolean statementSanitizationEnabled;
private final boolean emitExperimentalHttpClientMetrics;
private final boolean emitExperimentalHttpServerMetrics;
private final boolean captureEnduser;

CommonConfig(InstrumentationConfig config) {
peerServiceResolver =
Expand Down Expand Up @@ -73,6 +74,8 @@ public static CommonConfig get() {
config.getBoolean("otel.instrumentation.http.client.emit-experimental-metrics", false);
emitExperimentalHttpServerMetrics =
config.getBoolean("otel.instrumentation.http.server.emit-experimental-metrics", false);
captureEnduser =
config.getBoolean("otel.instrumentation.common.capture-enduser.enabled", false);
}

public PeerServiceResolver getPeerServiceResolver() {
Expand Down Expand Up @@ -110,4 +113,8 @@ public boolean shouldEmitExperimentalHttpClientMetrics() {
public boolean shouldEmitExperimentalHttpServerMetrics() {
return emitExperimentalHttpServerMetrics;
}

public boolean shouldCaptureEnduser() {
return captureEnduser;
}
}
Loading