-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Workiva/collector-exporter
O11Y-992: OTEL Dart: Implement OTLP HTTP Reporter
- Loading branch information
Showing
29 changed files
with
312 additions
and
83 deletions.
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.