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

Add WithoutSubSpans option to NewClientTrace #879

Merged
merged 3 commits into from
Sep 2, 2021

Conversation

coryb
Copy link
Contributor

@coryb coryb commented Jul 11, 2021

This adds an optional behavior to NewClientTrace so that it only
adds events and annotations to the span found in SpanFromContext.
The default behavior remains unchanged, several sub-spans will be
created for each request. This optional behavior is useful when
tracing "complex" processes that have many http calls. In this case
the added sub-spans become "noise" and may distract from the overall
trace.

This also adds several useful attributes from data available
in the httptrace callbacks:

  • http.conn.reused - bool if connection was reused
  • http.conn.wasidle - bool if connection was idle
  • http.conn.idletime - if wasidle, duration of idletime
  • http.conn.start.network - start connection network type [tcp/udp]
  • http.conn.done.network - end connection network type [tcp/udp]
  • http.conn.done.addr - connection address when done
  • http.dns.addrs - list of addrs returned from dns lookup

Fixes #876

value := sliceToString(v)
if _, ok := ct.redactedHeaders[k]; ok {
// redact all non-space runes to 'x'
value = strings.Map(func(r rune) rune {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer if this wouldn't leak the length/spaces or waste space with long tokens. Just constant *** sgtm

Copy link
Member

Choose a reason for hiding this comment

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

I have even a stronger point of view. I think in such a case, the attribute should NOT be included at all. This is to ensure we do not leak any security-related internals.

Reasoning: open-telemetry/opentelemetry-specification#1502 (comment)

This would be also more in line with other specification recommendations such us:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now I have updated to use fixed **** value. We can instead drop those annotations completely, I dont really have a preference. If we drop them, I guess I would change the WithRedactedHeaders to WithIgnoredHeaders to alllow appending to the fixed list. We can also swap the default to not collect any headers unless a WithHeaders option is specified. For the edge case of trying to debug authentication-related issues, we could add WithRedactgnoredHeaders (or some such name) to keep headers in the spans but always hide the values.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer the redacted value instead of ignoring one. Seeing which requests were authenticated and which were not is an important common feature in tracing HTTP traffic and can point to issues.

@coryb coryb force-pushed the httptrace-without-subspans branch from 5801e3b to 70ab82b Compare July 12, 2021 15:11
@coryb coryb force-pushed the httptrace-without-subspans branch 2 times, most recently from 2ceef5c to d757e2b Compare July 13, 2021 15:22
@codecov
Copy link

codecov bot commented Jul 13, 2021

Codecov Report

Merging #879 (f89b79d) into main (061e903) will increase coverage by 0.1%.
The diff coverage is 77.4%.

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #879     +/-   ##
=======================================
+ Coverage   69.2%   69.4%   +0.1%     
=======================================
  Files         77      77             
  Lines       4850    4929     +79     
=======================================
+ Hits        3359    3423     +64     
- Misses      1353    1367     +14     
- Partials     138     139      +1     
Impacted Files Coverage Δ
...on/net/http/httptrace/otelhttptrace/clienttrace.go 77.6% <77.4%> (+1.7%) ⬆️

@pellared
Copy link
Member

The default behavior remains unchanged,

I think this is not true b/c of the default redactedHeaders.

Also is it possible to remove the default redactedHeaders if someone really wants to trace them (e.g. for some local testing)? I think that security should be "enabled" by default but there should always be an option to explicitly configure to some insecure settings.

@coryb
Copy link
Contributor Author

coryb commented Jul 14, 2021

The default behavior remains unchanged,

I think this is not true b/c of the default redactedHeaders.

True, there is a behaviour change due to the redacted headers. I didn't know about the leaking headers when I opened the issue and made that comment.

Also is it possible to remove the default redactedHeaders if someone really wants to trace them (e.g. for some local testing)? I think that security should be "enabled" by default but there should always be an option to explicitly configure to some insecure settings.

We could add a WithInsecureHeaders to disable the redaction and reset the current list. Motivated users could always just add an http.RoundTrip wrapper to their client that adds more attributes to the spans. Either option seems fine to me, curious if others have opinions...

@coryb coryb force-pushed the httptrace-without-subspans branch from d757e2b to cc0c21d Compare July 17, 2021 21:04
@coryb
Copy link
Contributor Author

coryb commented Jul 17, 2021

curious if others have opinions...

No response, so I went ahead and added WithInsecureHeaders to facilitate the "debugging auth issues" use-case. Also extended the tests to verify WithoutHeaders, WithRedactedHeaders, and the new WithInsecureHeaders so there should not be a drop in test coverage.

CHANGELOG.md Outdated Show resolved Hide resolved
@coryb coryb force-pushed the httptrace-without-subspans branch 3 times, most recently from a32efea to 2188076 Compare July 20, 2021 14:43
@coryb
Copy link
Contributor Author

coryb commented Jul 20, 2021

Updated lint issue that broke the tests, I forgot to run the precommit check but it is working now.

@coryb coryb force-pushed the httptrace-without-subspans branch from 2188076 to ea594c2 Compare July 27, 2021 20:00
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@coryb coryb force-pushed the httptrace-without-subspans branch from f87cd46 to a0dc0a0 Compare August 11, 2021 23:02
@thaJeztah
Copy link

@coryb needs a rebase

@coryb coryb force-pushed the httptrace-without-subspans branch from a0dc0a0 to 47dbbcc Compare August 20, 2021 01:37
@coryb
Copy link
Contributor Author

coryb commented Aug 20, 2021

Thanks for the ping, rebased, again. Hopefully we can get this merged in, please.

@coryb coryb force-pushed the httptrace-without-subspans branch 2 times, most recently from bbf1e35 to b8da8cd Compare August 20, 2021 01:44
@coryb
Copy link
Contributor Author

coryb commented Aug 20, 2021

Could someone please poke the workflow approval button so the test will run?

@coryb
Copy link
Contributor Author

coryb commented Aug 23, 2021

Can we please get this merged in? We have two approvals and tests are passing ... what more is left?

@thaJeztah
Copy link

@coryb needs a rebase (again 😞)

@coryb coryb force-pushed the httptrace-without-subspans branch from b8da8cd to 81f719d Compare August 30, 2021 14:58
coryb and others added 2 commits August 30, 2021 07:59
This adds an optional behavior to NewClientTrace so that it only
adds events and annotations to the span found in SpanFromContext.
The default behavior remains unchanged, several sub-spans will be
created for each request.  This optional behavior is useful when
tracing "complex" processes that have many http calls.  In this case
the added sub-spans become "noise" and may distract from the overall
trace.

This also adds several useful attributes from data available
in the httptrace callbacks:
    http.conn.reused - bool if connection was reused
    http.conn.wasidle - bool if connection was idle
    http.conn.idletime - if wasidle, duration of idletime
    http.conn.start.network - start connection network type [tcp/udp]
    http.conn.done.network - end connection network type [tcp/udp]
    http.conn.done.addr - connection address when done
    http.dns.addrs - list of addrs returned from dns lookup

Signed-off-by: coryb <cbennett@netflix.com>
On testing we learned that sensitive information was being stored
in the traces.  To prevent the security leak several security or
sensitive headers will now be redacted. These are the headers
redacted by default:
    Authorization
    WWW-Authenticate
    Proxy-Authenticate
    Proxy-Authorization
    Cookie
    Set-Cookie

Users can add more headers to redact with WithRedactedHeaders. To
disable adding headers to the span entirely users can use WithoutHeaders.

Signed-off-by: coryb <cbennett@netflix.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
@coryb coryb force-pushed the httptrace-without-subspans branch from 81f719d to 2756490 Compare August 30, 2021 15:02
@coryb
Copy link
Contributor Author

coryb commented Aug 30, 2021

Hi folks, I have rebased again to address merge conflicts on the CHANGELOG. It has now been a month since the last change other than the rebases, so this is pretty frustrating.

I need someone to poke the workflow approval button again.

@thaJeztah
Copy link

@pellared @Aneurysm9 are you able to help out to this PR moving? 🤗

@thaJeztah
Copy link

Thanks!

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

Successfully merging this pull request may close these issues.

otelhttptrace: allow tracing by adding events
5 participants