-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Tracing updates #11116
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
Tracing updates #11116
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,8 @@ | |
| import com.azure.core.util.Context; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.ServiceLoader; | ||
|
|
||
| /** | ||
|
|
@@ -17,14 +17,13 @@ | |
| */ | ||
| public final class TracerProxy { | ||
|
|
||
| private static final List<Tracer> TRACERS; | ||
| private static Tracer TRACER; | ||
|
|
||
| static { | ||
| ServiceLoader<Tracer> serviceLoader = ServiceLoader.load(Tracer.class); | ||
| List<Tracer> tracers = new ArrayList<>(); | ||
| for (Tracer tracer : serviceLoader) { | ||
| tracers.add(tracer); | ||
| if (serviceLoader != null) { | ||
| TRACER = serviceLoader.iterator().next(); | ||
| } | ||
| TRACERS = Collections.unmodifiableList(tracers); | ||
| } | ||
|
|
||
| private TracerProxy() { | ||
|
|
@@ -33,7 +32,7 @@ private TracerProxy() { | |
|
|
||
| /** | ||
| * A new tracing span is created for each {@link Tracer tracer} plugged into the SDK. | ||
| * | ||
| * <p> | ||
| * The {@code context} will be checked for information about a parent span. If a parent span is found, the new span | ||
| * will be added as a child. Otherwise, the parent span will be created and added to the {@code context} and any | ||
| * downstream {@code start()} calls will use the created span as the parent. | ||
|
|
@@ -44,12 +43,10 @@ private TracerProxy() { | |
| * @return An updated {@link Context} object. | ||
| */ | ||
| public static Context start(String methodName, Context context) { | ||
| Context local = context; | ||
| for (Tracer tracer : TRACERS) { | ||
| local = tracer.start(methodName, local); | ||
| if (TRACER == null) { | ||
| return context; | ||
| } | ||
|
|
||
| return local; | ||
| return TRACER.start(methodName, context); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -61,7 +58,10 @@ public static Context start(String methodName, Context context) { | |
| * @param context Additional metadata that is passed through the call stack. | ||
| */ | ||
| public static void setAttribute(String key, String value, Context context) { | ||
| TRACERS.forEach(tracer -> tracer.setAttribute(key, value, context)); | ||
| if (TRACER == null) { | ||
| return; | ||
| } | ||
| TRACER.setAttribute(key, value, context); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -72,7 +72,10 @@ public static void setAttribute(String key, String value, Context context) { | |
| * @param context Additional metadata that is passed through the call stack. | ||
| */ | ||
| public static void end(int responseCode, Throwable error, Context context) { | ||
| TRACERS.forEach(tracer -> tracer.end(responseCode, error, context)); | ||
| if (TRACER == null) { | ||
| return; | ||
| } | ||
| TRACER.end(responseCode, error, context); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -84,11 +87,9 @@ public static void end(int responseCode, Throwable error, Context context) { | |
| * @return An updated {@link Context} object. | ||
| */ | ||
| public static Context setSpanName(String spanName, Context context) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this API return
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Context local = context; | ||
| for (Tracer tracer : TRACERS) { | ||
| local = tracer.setSpanName(spanName, context); | ||
| if (TRACER == null) { | ||
| return context; | ||
| } | ||
|
|
||
| return local; | ||
| return TRACER.setSpanName(spanName, context); | ||
| } | ||
| } | ||
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.
Do we have any mechanisms available which will ensure a certain tracer is loaded if I happen to bring multiple? This can be a follow-up as it is definitely an edge case.
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.
Yeah, I think we could add a feature where a user preference could be preferred for a single implementation if multiple found.
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.
Or, if there are multiple instances of tracer implementations, should we support all of them? Create spans on each tracer implementation?
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.
There is no real use case to support multiple implementations, as users would always tie it with a single implementation of tracer to an exporter.
It brings in a lot of complexity for the users of the library to actually look to configure each span with a single tracer implementation and then the corresponding exporter for that tracer. As mentioned above, not a real use case and something only Java SDK was supporting.