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 1 commit
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
3 changes: 2 additions & 1 deletion instrumentation/servlet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
## 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.enduser-span-attributes` | Boolean | `false` | Enable the capture of `enduser.id` span attribute. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think it makes sense to generalize this from .servlet. to .common. in anticipation of #9400?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but was unclear where the common flag could be documented (I guess it is in the website repo). So just added it for the servlet now. What do you suggest for the flag name? Is otel.instrumentation.common.capture-enduser.enabled that was suggested in #9400 fine?

Copy link
Member

@trask trask Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is otel.instrumentation.common.capture-enduser.enabled that was suggested in #9400 fine?

👍

| `otel.instrumentation.servlet.experimental.capture-request-parameters` | List | Empty | Request parameters to be captured (experimental). |

### A word about version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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 (!ServletAdditionalAttributesExtractor.CAPTURE_EXPERIMENTAL_ENDUSER_SPAN_ATTRIBUTES) {
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 @@ -22,6 +22,10 @@ public class ServletAdditionalAttributesExtractor<REQUEST, RESPONSE>
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
InstrumentationConfig.get()
.getBoolean("otel.instrumentation.servlet.experimental-span-attributes", false);
static final boolean CAPTURE_EXPERIMENTAL_ENDUSER_SPAN_ATTRIBUTES =
InstrumentationConfig.get()
.getBoolean("otel.instrumentation.servlet.experimental.enduser-span-attributes", false);

private static final AttributeKey<Long> SERVLET_TIMEOUT = longKey("servlet.timeout");

private final ServletAccessor<REQUEST, RESPONSE> accessor;
Expand All @@ -43,11 +47,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 (CAPTURE_EXPERIMENTAL_ENDUSER_SPAN_ATTRIBUTES) {
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