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

Recommend pattern to redact query string parameters #2791

Open
ericksoen opened this issue Jan 14, 2022 · 6 comments
Open

Recommend pattern to redact query string parameters #2791

ericksoen opened this issue Jan 14, 2022 · 6 comments
Labels
question Further information is requested

Comments

@ericksoen
Copy link

Question

We're evaluating a migration from New Relic APM agents to OpenTelemetry. This APM agent provides fine-grained control over what properties are included or excluded to our telemetry. This includes properties like query string parameters, ports, etc.

I see that the dotnet Http instrumentation library provides filters to remove requests entirely and also an Enrich option to add additional properties.

I've been able to hijack this Enrich property to override the value for the http.url to remove query string params—this seems to accomplish the desired effect. I'm curious if there are any recommended patterns for how to accomplish this in the instrumentation library itself or if it is better handled via attribute processors in an OTEL config.

.AddHttpClientInstrumentation((options) => options.Enrich = (activity, eventName, rawObject) =>
{
    if (eventName.Equals("OnStartActivity"))
    {
        if (rawObject is HttpRequestMessage request)
        {
            var redactedUrl = request.RequestUri.OriginalString.Split("?")[0];
            activity.SetTag("http.url", redactedUrl);
        }
    }
})

Describe any aspect of your environment relevant to the question.

  • Dotnet WebCore31 application
  • OpenTelemetry.Instrumentation.Http version 1.0.0-rc8

What are you trying to achieve?

Remove query string parameters that are automatically added via HTTP client instrumentation (preferably with minimal application code on my part 😁)

Additional Context

N/A

@ericksoen ericksoen added the question Further information is requested label Jan 14, 2022
@cijothomas
Copy link
Member

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Jan 25, 2022
@cijothomas cijothomas removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Jan 27, 2022
@stevejgordon
Copy link
Contributor

stevejgordon commented Jul 8, 2024

@martinjt, this is another issue I think we can close. Things have moved on since this was opened.

For inbound HTTP requests, query string parameters are now redacted by default when added to the url.query attribute:

Activity.Tags:
    server.address: localhost
    server.port: 7036
    url.query: ?test1=Redacted&test2=Redacted
    http.request.method: GET
    url.scheme: https
    url.path: /weatherforecast
    network.protocol.version: 2
    user_agent.original: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
    http.route: /weatherforecast
    http.response.status_code: 200

For outbound HTTP via HttpClient, they are redacted in url.full:

Activity.Tags:
    http.request.method: GET
    server.address: www.google.com
    server.port: 443
    url.full: https://www.google.com/?query1=Redacted&query2=Redacted
    network.protocol.version: 1.1
    http.response.status_code: 200

@swythan
Copy link

swythan commented Jul 8, 2024

That's a very blunt instrument, though. If you want to include everything except one query parameter (e.g. because chromium refuses to allow browser JS to set auth headers on websocket connections) then you have to "hijack" The enrichment mechanism as in the OP.

@abatishchev
Copy link

@stevejgordon

For inbound HTTP requests, query string parameters are now redacted by default

Is there a way to opt out?

@swythan
Copy link

swythan commented Oct 19, 2024

@stevejgordon

For inbound HTTP requests, query string parameters are now redacted by default

Is there a way to opt out?

OTEL_DOTNET_EXPERIMENTAL_ASPNETCORE_DISABLE_URL_QUERY_REDACTION

See:

https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/docs/config.md#instrumentation-options

#5532

@abatishchev
Copy link

thanks, @swythan! I asked and then found the corresponding environment variables myself.

I asked a question about them here: open-telemetry/semantic-conventions#860 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants