GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Supporting Baggage for Instrumentations used in Weblog Tests by mhlidd · Pull Request #8773 · DataDog/dd-trace-java

Supporting Baggage for Instrumentations used in Weblog Tests #8773

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.

Sign up for GitHub

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

Merged
mhlidd merged 15 commits into master from mhlidd/migrate_tomcat_okhttp
May 20, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Supporting Baggage for Instrumentations used in Weblog Tests #8773

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
54cdafc
supporting baggage in weblog related instrumentations
mhlidd May 6, 2025
16094c9
simplifying startSpan
mhlidd May 6, 2025
ed234d3
adding support for AzureFunctionsInstrumentation
mhlidd May 6, 2025
a7a35a6
cleanup
mhlidd May 6, 2025
8a5c90f
updateing grizzly instrumentations
mhlidd May 6, 2025
aacc0a0
updating PR comments and addressing failing unit tests
mhlidd May 7, 2025
2d3aed6
fixing ambiguous overloading tests
mhlidd May 7, 2025
0968d40
logging
mhlidd May 8, 2025
7a956f7
logging 2
mhlidd May 8, 2025
e2fb44c
spotless
mhlidd May 8, 2025
6b9b6e1
spotlesS
mhlidd May 12, 2025
0bb7df6
updating tests
mhlidd May 12, 2025
9b14d97
PR comments
mhlidd May 14, 2025
9cb9f80
Merge branch 'master' into mhlidd/migrate_tomcat_okhttp
mhlidd May 19, 2025
c2124fa
Merge branch 'master' into mhlidd/migrate_tomcat_okhttp
mhlidd May 20, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

31 changes: 30 additions & 1 deletion 31 .../src/main/java/datadog/trace/bootstrap/instrumentation/decorator/HttpServerDecorator.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package datadog.trace.bootstrap.instrumentation.decorator;

import static datadog.context.Context.root;
import static datadog.context.propagation.Propagators.defaultPropagator;
import static datadog.trace.api.cache.RadixTreeCache.UNSET_STATUS;
import static datadog.trace.api.datastreams.DataStreamsContext.fromTags;
import static datadog.trace.api.gateway.Events.EVENTS;
Expand All @@ -8,6 +10,7 @@
import static datadog.trace.bootstrap.instrumentation.decorator.http.HttpResourceDecorator.HTTP_RESOURCE_DECORATOR;

import datadog.appsec.api.blocking.BlockingException;
import datadog.context.Context;
import datadog.trace.api.Config;
import datadog.trace.api.DDTags;
import datadog.trace.api.function.TriConsumer;
Expand Down Expand Up @@ -124,6 +127,7 @@ protected AgentTracer.TracerAPI tracer() {
return AgentTracer.get();
}

/** Deprecated. Use {@link #extractContext(REQUEST_CARRIER)} instead. */
public AgentSpanContext.Extracted extract(REQUEST_CARRIER carrier) {
AgentPropagation.ContextVisitor<REQUEST_CARRIER> getter = getter();
if (null == carrier || null == getter) {
Expand All @@ -132,7 +136,18 @@ public AgentSpanContext.Extracted extract(REQUEST_CARRIER carrier) {
return extractContextAndGetSpanContext(carrier, getter);
}

/** Deprecated. Use {@link #startSpan(String, Object, AgentSpanContext.Extracted)} instead. */
/**
* Will be renamed to #extract(REQUEST_CARRIER) when refactoring of instrumentation's is complete
*/
public Context extractContext(REQUEST_CARRIER carrier) {
Comment thread
mhlidd marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

AgentPropagation.ContextVisitor<REQUEST_CARRIER> getter = getter();
if (null == carrier || null == getter) {
return root();
}
return defaultPropagator().extract(root(), carrier, getter);
}

/** Deprecated. Use {@link #startSpanFromContext(String, Object, Context)} instead. */
@Deprecated
public AgentSpan startSpan(REQUEST_CARRIER carrier, AgentSpanContext.Extracted context) {
return startSpan("http-server", carrier, context);
Expand All @@ -155,6 +170,20 @@ public AgentSpan startSpan(
return span;
}

/**
* Will be renamed to #startSpan(String, REQUEST_CARRIER, Context) when refactoring of
* instrumentation's is complete
*/
public AgentSpan startSpanFromContext(
String instrumentationName, REQUEST_CARRIER carrier, Context context) {
return startSpan(instrumentationName, carrier, getSpanContext(context));
}

public AgentSpanContext.Extracted getSpanContext(Context context) {
AgentSpan extractedSpan = AgentSpan.fromContext(context);
return extractedSpan == null ? null : (AgentSpanContext.Extracted) extractedSpan.context();
}

public AgentSpan onRequest(
final AgentSpan span,
final CONNECTION connection,
Expand Down
4 changes: 3 additions & 1 deletion 4 ...tion/okhttp-3/src/main/java/datadog/trace/instrumentation/okhttp3/TracingInterceptor.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static datadog.trace.instrumentation.okhttp3.OkHttpClientDecorator.OKHTTP_REQUEST;
import static datadog.trace.instrumentation.okhttp3.RequestBuilderInjectAdapter.SETTER;

import datadog.context.Context;
import datadog.trace.api.datastreams.DataStreamsContext;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
Expand All @@ -31,7 +32,8 @@ public Response intercept(final Chain chain) throws IOException {

final Request.Builder requestBuilder = chain.request().newBuilder();
DataStreamsContext dsmContext = DataStreamsContext.fromTags(CLIENT_PATHWAY_EDGE_TAGS);
defaultPropagator().inject(span.with(dsmContext), requestBuilder, SETTER);
defaultPropagator()
Comment thread

@PerfectSlayer PerfectSlayer May 14, 2025

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

FYI: I might refactor this part by introducing an inject method in helpers.
It will be the mirror operation of extract, and will allow to deal with the DSM context in a single location rather than all instrumentations.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcculls and mhlidd reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
.inject(Context.current().with(span).with(dsmContext), requestBuilder, SETTER);

final Response response;
try {
Expand Down
18 changes: 11 additions & 7 deletions 18 ...t-5.5/src/main/java/datadog/trace/instrumentation/tomcat/TomcatServerInstrumentation.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import com.google.auto.service.AutoService;
import datadog.context.Context;
import datadog.context.ContextScope;
import datadog.trace.agent.tooling.ExcludeFilterProvider;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.agent.tooling.InstrumenterModule;
import datadog.trace.agent.tooling.muzzle.Reference;
import datadog.trace.api.CorrelationIdentifier;
import datadog.trace.api.GlobalTracer;
import datadog.trace.api.gateway.Flow;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
Expand Down Expand Up @@ -114,19 +115,22 @@ public void methodAdvice(MethodTransformer transformer) {
public static class ServiceAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope onService(@Advice.Argument(0) org.apache.coyote.Request req) {
public static ContextScope onService(@Advice.Argument(0) org.apache.coyote.Request req) {

Object existingSpan = req.getAttribute(DD_SPAN_ATTRIBUTE);
if (existingSpan instanceof AgentSpan) {
// Request already gone through initial processing, so just activate the span.
return activateSpan((AgentSpan) existingSpan);
}

final AgentSpanContext.Extracted extractedContext = DECORATE.extract(req);
req.setAttribute(DD_EXTRACTED_CONTEXT_ATTRIBUTE, extractedContext);
final Context extractedContext = DECORATE.extractContext(req);
// TODO: Migrate setting DD_EXTRACTED_CONTEXT_ATTRIBUTE from AgentSpanContext.Extracted to
// Context
req.setAttribute(DD_EXTRACTED_CONTEXT_ATTRIBUTE, DECORATE.getSpanContext(extractedContext));

final AgentSpan span = DECORATE.startSpanFromContext("http-server", req, extractedContext);
final ContextScope scope = extractedContext.with(span).attach();

final AgentSpan span = DECORATE.startSpan(req, extractedContext);
final AgentScope scope = activateSpan(span);
// This span is finished when Request.recycle() is called by RequestInstrumentation.
DECORATE.afterStart(span);

Expand All @@ -137,7 +141,7 @@ public static AgentScope onService(@Advice.Argument(0) org.apache.coyote.Request
}

@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
public static void closeScope(@Advice.Enter final AgentScope scope) {
public static void closeScope(@Advice.Enter final ContextScope scope) {
scope.close();
}

Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.