-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Doc update tracing #5632
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
Merged
Merged
Doc update tracing #5632
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4935d71
add tests and docs
samvaity b296dd4
move process kind to util tracing
samvaity 865383e
fixing spotbugs
samvaity 9464a12
code snippet changes
samvaity b0d58b0
fix checkstyle
samvaity 67212e2
review comments
samvaity d96bea2
update changelog
samvaity 25d31d1
add paragraph tags
samvaity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...e/implementation/tracing/ProcessKind.java → .../azure/core/util/tracing/ProcessKind.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
...re/azure-core/src/samples/java/com/azure/core/util/tracing/TracerJavaDocCodeSnippets.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.core.util.tracing; | ||
|
|
||
| import com.azure.core.util.Context; | ||
|
|
||
| import static com.azure.core.util.tracing.Tracer.OPENCENSUS_SPAN_NAME_KEY; | ||
| import static com.azure.core.util.tracing.Tracer.ENTITY_PATH; | ||
| import static com.azure.core.util.tracing.Tracer.OPENCENSUS_SPAN_KEY; | ||
| import static com.azure.core.util.tracing.Tracer.HOST_NAME; | ||
| import static com.azure.core.util.tracing.Tracer.SPAN_CONTEXT; | ||
| import static com.azure.core.util.tracing.Tracer.DIAGNOSTIC_ID_KEY; | ||
|
|
||
| /** | ||
| * Contains code snippets when generating javadocs through doclets for {@link Tracer}. | ||
| */ | ||
| public class TracerJavaDocCodeSnippets { | ||
| final Tracer tracer = new TracerImplementation(); | ||
|
|
||
| /** | ||
| * Code snippet for {@link Tracer#start(String, Context, ProcessKind)} and {@link Tracer#start(String, Context)} | ||
| */ | ||
| public void startTracingSpan() { | ||
| // BEGIN: com.azure.core.util.tracing.start#string-context | ||
| // pass the current tracing span context to the calling method | ||
| Context traceContext = new Context(OPENCENSUS_SPAN_KEY, "<user-current-span>"); | ||
| // start a new tracing span with the given method name and explicit parent span | ||
| Context updatedContext = tracer.start("azure.keyvault.secrets/setsecret", traceContext); | ||
| System.out.printf("Span returned in the context object: %s%n", | ||
| updatedContext.getData(OPENCENSUS_SPAN_KEY).get().getClass()); | ||
|
samvaity marked this conversation as resolved.
Outdated
|
||
| // END: com.azure.core.util.tracing.start#string-context | ||
|
|
||
| // BEGIN: com.azure.core.util.tracing.start#string-context-processKind-SEND | ||
| // pass the current tracing span and request metadata to the calling method | ||
| Context sendContext = new Context(OPENCENSUS_SPAN_KEY, "<user-current-span>") | ||
| .addData(ENTITY_PATH, "entity-path").addData(HOST_NAME, "hostname"); | ||
|
|
||
| // start a new tracing span with explicit parent, sets the request attributes on the span and sets the span | ||
| // kind to client when process kind SEND | ||
| Context updatedSendContext = tracer.start("azure.eventhubs.send", sendContext, ProcessKind.SEND); | ||
| System.out.printf("Span returned in the context object: %s%n", | ||
| updatedSendContext.getData(OPENCENSUS_SPAN_KEY).get()); | ||
| // END: com.azure.core.util.tracing.start#string-context-processKind-SEND | ||
|
|
||
| // BEGIN: com.azure.core.util.tracing.start#string-context-processKind-RECEIVE | ||
| // start a new tracing span with explicit parent, sets the diagnostic Id (traceparent headers) on the current | ||
| // context when process kind RECEIVE | ||
| Context updatedReceiveContext = tracer.start("azure.eventhubs.receive", traceContext, | ||
| ProcessKind.RECEIVE); | ||
| System.out.printf("Diagnostic Id: {} %s%n", (String) updatedReceiveContext.getData(DIAGNOSTIC_ID_KEY).get()); | ||
|
samvaity marked this conversation as resolved.
Outdated
|
||
| // END: com.azure.core.util.tracing.start#string-context-processKind-RECEIVE | ||
|
|
||
| // BEGIN: com.azure.core.util.tracing.start#string-context-processKind-PROCESS | ||
| // start a new tracing span with remote parent and uses the span in the current context to return a scope | ||
| // when process kind PROCESS | ||
| Context processContext = new Context(OPENCENSUS_SPAN_KEY, "<user-current-span>") | ||
| .addData(SPAN_CONTEXT, "<user-current-span-context>"); | ||
| Context updatedProcessContext = tracer.start("azure.eventhubs.process", processContext, | ||
| ProcessKind.PROCESS); | ||
| System.out.printf("Scope: {} %s%n", updatedProcessContext.getData("scope").get().getClass()); | ||
|
samvaity marked this conversation as resolved.
Outdated
|
||
| // END: com.azure.core.util.tracing.start#string-context-processKind-PROCESS | ||
| } | ||
|
|
||
| /** | ||
| * Code snippet for {@link Tracer#end(int, Throwable, Context)} and {@link Tracer#end(String, Throwable, Context)} | ||
| */ | ||
| public void endTracingSpan() { | ||
| // BEGIN: com.azure.core.util.tracing.end#int-throwable-context | ||
| // context containing the current tracing span to end | ||
| Context traceContext = new Context(OPENCENSUS_SPAN_KEY, "<user-current-span>"); | ||
|
|
||
| // completes the tracing span with the passed response status code | ||
| tracer.end(200, null, traceContext); | ||
| // END: com.azure.core.util.tracing.end#int-throwable-context | ||
|
|
||
| // BEGIN: com.azure.core.util.tracing.end#string-throwable-context | ||
| // context containing the current tracing span to end | ||
| // completes the tracing span with the passed status message | ||
| tracer.end("success", null, traceContext); | ||
| // END: com.azure.core.util.tracing.end#string-throwable-context | ||
| } | ||
|
|
||
| /** | ||
| * Code snippet for {@link Tracer#setSpanName(String, Context)} | ||
| */ | ||
| public void setSpanName() { | ||
| // BEGIN: com.azure.core.util.tracing.setSpanName#string-context | ||
| // Sets the span name of the returned span on the context object, with key OPENCENSUS_SPAN_NAME_KEY | ||
| Context context = tracer.setSpanName("test-span-method", Context.NONE); | ||
| System.out.printf("Span name: %s%n", (String) context.getData(OPENCENSUS_SPAN_NAME_KEY).get()); | ||
| // END: com.azure.core.util.tracing.setSpanName#string-context | ||
| } | ||
|
|
||
| /** | ||
| * Code snippet for {@link Tracer#addLink(Context)} | ||
| */ | ||
| public void addLink() { | ||
| // BEGIN: com.azure.core.util.tracing.addLink#context | ||
| // use the parent context containing the current tracing span to start a child span | ||
| Context parentContext = new Context(OPENCENSUS_SPAN_KEY, "<user-current-span>"); | ||
| // use the returned span context information of the current tracing span to link | ||
| Context spanContext = tracer.start("test.method", parentContext, ProcessKind.RECEIVE); | ||
|
|
||
| // Adds a link between multiple span's using the span context information of the Span | ||
| // For each event processed, add a link with the created spanContext | ||
| tracer.addLink(spanContext); | ||
| // END: com.azure.core.util.tracing.addLink#context | ||
| } | ||
|
|
||
| /** | ||
| * Code snippet for {@link Tracer#extractContext(String, Context)} | ||
| */ | ||
| public void extractContext() { | ||
| // BEGIN: com.azure.core.util.tracing.extractContext#string-context | ||
| // Extracts the span context information from the passed diagnostic Id that can be used for linking spans. | ||
| Context spanContext = tracer.extractContext("valid-diagnostic-id", Context.NONE); | ||
| System.out.printf("Span context of the current tracing span: %s%n", spanContext.getData(SPAN_CONTEXT).get()); | ||
| // END: com.azure.core.util.tracing.extractContext#string-context | ||
| } | ||
|
|
||
| //Noop Tracer | ||
| private static final class TracerImplementation implements Tracer { | ||
| @Override | ||
| public Context start(String methodName, Context context) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Context start(String methodName, Context context, ProcessKind processKind) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void end(int responseCode, Throwable error, Context context) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void end(String errorCondition, Throwable error, Context context) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void setAttribute(String key, String value, Context context) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public Context setSpanName(String spanName, Context context) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void addLink(Context context) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public Context extractContext(String diagnosticId, Context context) { | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.