-
Notifications
You must be signed in to change notification settings - Fork 36
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
PPI-203 : deprecate context manager and implement attach/detach APIs #192
Closed
Closed
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6a969ec
deprecate context manager and implement attach/detach APIs
blakeroberts-wk d1536f1
add contextFromZone()
blakeroberts-wk 9d7a386
add warning log on detach mismatch
blakeroberts-wk fa08afb
fix wrong context propagated to callback of traceContext and traceCon…
blakeroberts-wk bd9e07f
add attach/detach to trace helper functions
blakeroberts-wk dffab4b
use empty context stack when forking a zone and traverse zones for th…
blakeroberts-wk d7ce327
fix null exception when calling active within a nested zone and fix d…
blakeroberts-wk d0149a8
add stream context propagation example
blakeroberts-wk 75c43ef
rename active to current and move current, attach, and detach to stat…
blakeroberts-wk 136a00d
remove sealed annoatation from ContextKey class
blakeroberts-wk f21326d
Merge branch 'master' into attach-detach
blakeroberts-wk 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 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 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,7 @@ | ||
# Attach Detach Context Example | ||
|
||
This example demonstrates context propagation using the attach/detach context APIs through multiple zones. | ||
|
||
The example produces two traces represented by the following diagram: | ||
|
||
 |
This file contains 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,49 @@ | ||
// Copyright 2021-2022 Workiva. | ||
// Licensed under the Apache License, Version 2.0. Please see https://github.com/Workiva/opentelemetry-dart/blob/master/LICENSE for more information | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:opentelemetry/api.dart'; | ||
import 'package:opentelemetry/sdk.dart' | ||
show ConsoleExporter, SimpleSpanProcessor, TracerProviderBase; | ||
|
||
void main() { | ||
final tp = TracerProviderBase( | ||
processors: [SimpleSpanProcessor(ConsoleExporter())]), | ||
tracer = tp.getTracer('instrumentation-name'); | ||
|
||
final span = tracer.startSpan('root-zone-attached-span')..end(); | ||
final token = attach(contextWithSpan(active, span)); | ||
|
||
final completer = Completer(); | ||
|
||
// zone A | ||
zoneWithContext(active).run(() { | ||
final span = tracer.startSpan('zone-a-attached-span')..end(); | ||
final context = contextWithSpan(active, span); | ||
|
||
// zone B | ||
zoneWithContext(context).run(() { | ||
tracer.startSpan('zone-b-span').end(); | ||
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. It feels like this zone-b-span should be a child of zone-a-attached-span? But the README says it is not. I suggest to use the same span names in the README. |
||
completer.future.then((_) { | ||
tracer.startSpan('zone-b-post-detach-span').end(); | ||
}); | ||
}); | ||
|
||
final token = attach(context); | ||
tracer.startSpan('zone-a-attached-child-span').end(); | ||
if (!detach(token)) { | ||
throw Exception('Failed to detach context'); | ||
} | ||
|
||
tracer.startSpan('zone-a-post-detach-span').end(); | ||
}); | ||
|
||
if (!detach(token)) { | ||
throw Exception('Failed to detach context'); | ||
} | ||
|
||
completer.complete(); | ||
|
||
tracer.startSpan('root-zone-post-detach-span').end(); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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.
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.
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.
I would advise against shadowing the variables.
span and token are both shadowed and that certainly makes the example a little harder to read.
One way you could tackle this is to split the zone function. The other is just using more unique names.
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.
Fair. I can update the variable names. Though I'm wondering if I should scrap this example for something more contrived. Like pretend to do an app "setup" or "load" or something 🤷