-
Notifications
You must be signed in to change notification settings - Fork 33
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
O11Y-992: OTEL Dart: Implement OTLP HTTP Reporter #6
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.dart_tool | ||
.packages | ||
pubspec.lock | ||
pubspec.lock | ||
lib/src/sdk/trace/exporters/opentelemetry |
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,3 @@ | ||
[submodule "lib/src/sdk/trace/exporters/opentelemetry-proto"] | ||
path = lib/src/sdk/trace/exporters/opentelemetry-proto | ||
url = [email protected]:open-telemetry/opentelemetry-proto.git |
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 |
---|---|---|
@@ -1,13 +1,20 @@ | ||
deps: | ||
@pub get | ||
init: | ||
git submodule update --init | ||
pub get | ||
pub global activate protoc_plugin | ||
cd lib/src/sdk/trace/exporters && \ | ||
protoc --proto_path opentelemetry-proto \ | ||
--dart_out . \ | ||
opentelemetry-proto/opentelemetry/proto/common/v1/common.proto \ | ||
opentelemetry-proto/opentelemetry/proto/collector/trace/v1/trace_service.proto \ | ||
opentelemetry-proto/opentelemetry/proto/trace/v1/trace.proto \ | ||
opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto | ||
|
||
analyze-lib: | ||
analyze: | ||
@dart analyze ./lib | ||
|
||
analyze-test: | ||
@dart analyze ./test | ||
|
||
test: analyze-lib | ||
test: | ||
@dart test ./test --chain-stack-traces | ||
|
||
.PHONY: deps analyze-lib analyze-test test | ||
.PHONY: init analyze test |
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
include: package:workiva_analysis_options/v1.recommended.yaml | ||
analyzer: | ||
exclude: | ||
- src/sdk/trace/exporters/opentelemetry |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/// Generator capable of creating OTel compliant IDs. | ||
abstract class IdGenerator { | ||
/// Generate an ID for a Span. | ||
String generateSpanId(); | ||
List<int> generateSpanId(); | ||
|
||
/// Generate an ID for a trace. | ||
String generateTraceId(); | ||
List<int> generateTraceId(); | ||
} |
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
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,82 @@ | ||
import 'package:http/http.dart' as http; | ||
|
||
import '../../../api/trace/span.dart'; | ||
import '../../../api/trace/span_status.dart'; | ||
|
||
import 'opentelemetry/proto/collector/trace/v1/trace_service.pb.dart'; | ||
import 'opentelemetry/proto/common/v1/common.pb.dart'; | ||
import 'opentelemetry/proto/resource/v1/resource.pb.dart'; | ||
import 'opentelemetry/proto/trace/v1/trace.pb.dart' as pb; | ||
import 'span_exporter.dart'; | ||
|
||
class CollectorExporter implements SpanExporter { | ||
Uri uri; | ||
http.Client client; | ||
var _isShutdown = false; | ||
|
||
CollectorExporter(this.uri, {http.Client httpClient}) { | ||
client = httpClient ?? http.Client(); | ||
} | ||
|
||
@override | ||
void export(List<Span> spans) { | ||
if (_isShutdown) { | ||
return; | ||
} | ||
|
||
if (spans.isEmpty) { | ||
return; | ||
} | ||
|
||
final pbSpans = <pb.Span>[]; | ||
for (var i = 0; i < spans.length; i++) { | ||
pbSpans.add(_spanToProtobuf(spans[i])); | ||
} | ||
|
||
final body = ExportTraceServiceRequest(resourceSpans: [ | ||
pb.ResourceSpans( | ||
resource: Resource(attributes: [ | ||
KeyValue( | ||
key: 'service.name', | ||
value: AnyValue(stringValue: spans[0].tracer.name)) | ||
]), | ||
instrumentationLibrarySpans: [ | ||
pb.InstrumentationLibrarySpans(spans: pbSpans) | ||
]) | ||
]); | ||
|
||
client.post(uri, | ||
body: body.writeToBuffer(), | ||
headers: {'Content-Type': 'application/x-protobuf'}); | ||
} | ||
|
||
pb.Span _spanToProtobuf(Span span) { | ||
pb.Status_StatusCode statusCode; | ||
|
||
switch (span.status.code) { | ||
case StatusCode.UNSET: | ||
statusCode = pb.Status_StatusCode.STATUS_CODE_UNSET; | ||
break; | ||
case StatusCode.ERROR: | ||
statusCode = pb.Status_StatusCode.STATUS_CODE_ERROR; | ||
break; | ||
case StatusCode.OK: | ||
statusCode = pb.Status_StatusCode.STATUS_CODE_OK; | ||
break; | ||
} | ||
|
||
return pb.Span( | ||
traceId: span.spanContext.traceId, | ||
spanId: span.spanContext.spanId, | ||
parentSpanId: span.parentSpanId, | ||
name: span.name, | ||
startTimeUnixNano: span.startTime * 1000, | ||
endTimeUnixNano: span.endTime * 1000, | ||
status: pb.Status(code: statusCode, message: span.status.description)); | ||
} | ||
|
||
@override | ||
void shutdown() { | ||
_isShutdown = true; | ||
} | ||
} |
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
Submodule opentelemetry-proto
added at
867249
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
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
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.
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.
Rather than give a span the whole tracer, I think it makes sense to give the span
resource
andinstrumentationLibrary
attributes which can be serialized. This would be inline with the js version: https://github.com/open-telemetry/opentelemetry-js/blob/30733df5cbddb8bc60da5bc7a65f25a182f036d8/packages/opentelemetry-exporter-collector/src/transform.ts#L305-L324There 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.
mostly so we don't expose the api
tracer.startSpan().tracer.StartSpan()
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.
Good catch! We should correct this once https://jira.atl.workiva.net/browse/O11Y-994 is completed. I believe that has some work to include Resources, so we can easily adjust afterward.