Skip to content

Conversation

@carterkozak
Copy link
Contributor

Before this PR

Many requests may share a single traceId, there was no identifying information to distinguish between requests.

After this PR

==COMMIT_MSG==
Tracing uniquely identifies requests
==COMMIT_MSG==

Possible downsides?

  • The request identifier is arguably not a tracing concern, implementing it at this layer is a matter of convenience.We already wrap requests and executors with tracing-aware components, and tell tracing when a request begins and ends, making tracing an ideal candidate to house this identifier.
  • Possible performance cost of generating another unique identifier for each request.

@carterkozak carterkozak requested review from ferozco and iamdanfox July 13, 2020 19:14
@changelog-app
Copy link

changelog-app bot commented Jul 13, 2020

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Tracing uniquely identifies requests with request metadata and a _requestId MDC property.

Check the box to generate changelog(s)

  • Generate changelog entry

@carterkozak
Copy link
Contributor Author

needs more test coverage

public static final String TRACE_SAMPLED_KEY = "_sampled";

/** The key under which tracing request ids are inserted into SLF4J {@link org.slf4j.MDC MDCs}. */
public static final String REQUEST_ID_KEY = "_requestId";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will appear in every log line. Do we want to abbreviate it in some way? As written it's self-explanatory.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like it as is

/**
* Initializes the current thread's trace, erasing any previously accrued open spans.
*
* @deprecated Use {@link #initTraceWithSpan(Observability, String, String, SpanType)}
Copy link
Contributor

Choose a reason for hiding this comment

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

there seems to be relatively little usage of this method, with the majority of it being in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately many tests attempt to peel back layers of abstraction rather than testing results. These methods are only really used for server-incoming requests where we have prior knowledge of a request identifier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry my comment was unclear, I was looking at internal usage across the fleet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that makes sense 👍

if (!requestId.isPresent()) {
throw new SafeIllegalStateException("No requestId is set", SafeArg.of("span", detachedSpan));
}
exchange.putAttachment(TracingAttachments.REQUEST_ID, requestId.get());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add a response header as well for easier debugging

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'm not sure I'm ready to modify the wire api at this point, the traceid is more actionable in the majority of cases as an api consumer while the requestId gives us the ability to do stronger structured analysis.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, we can add it later if needed

@ferozco
Copy link
Contributor

ferozco commented Jul 14, 2020

👍 looks great!

@bulldozer-bot bulldozer-bot bot merged commit 9eecbc7 into develop Jul 14, 2020
@bulldozer-bot bulldozer-bot bot deleted the ckozak/request_identifier branch July 14, 2020 15:36
@svc-autorelease
Copy link
Collaborator

Released 4.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants