Skip to content

Commit

Permalink
Merge pull request #24 from michaelyeager-wf/myeager-wf/otel-global
Browse files Browse the repository at this point in the history
API For Registering Global Instance
  • Loading branch information
rmconsole7-wk authored Nov 11, 2021
2 parents ff7da68 + 5ff2864 commit 6fbdadc
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 20 deletions.
2 changes: 2 additions & 0 deletions lib/api.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export 'src/api/common/attribute.dart' show Attribute;
export 'src/api/common/attributes.dart' show Attributes;
export 'src/api/context/context.dart' show Context;
export 'src/api/exporters/span_exporter.dart' show SpanExporter;
export 'src/api/propagation/extractors/text_map_getter.dart' show TextMapGetter;
export 'src/api/propagation/injectors/text_map_setter.dart' show TextMapSetter;
export 'src/api/propagation/text_map_propagator.dart' show TextMapPropagator;
export 'src/api/span_processors/span_processor.dart' show SpanProcessor;
export 'src/api/trace/id_generator.dart' show IdGenerator;
export 'src/api/trace/span.dart' show Span;
export 'src/api/trace/span_context.dart' show SpanContext;
Expand Down
2 changes: 2 additions & 0 deletions lib/sdk.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export 'src/sdk/common/attribute.dart' show Attribute;
export 'src/sdk/open_telemetry.dart'
show registerGlobalTracerProvider, globalTracerProvider;
export 'src/sdk/trace/exporters/collector_exporter.dart' show CollectorExporter;
export 'src/sdk/trace/exporters/console_exporter.dart' show ConsoleExporter;
export 'src/sdk/trace/propagation/w3c_trace_context_propagator.dart'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../../api/trace/span.dart';
import '../trace/span.dart';

abstract class SpanExporter {
void export(List<Span> spans);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../../api/trace/span.dart';
import '../trace/span.dart';

abstract class SpanProcessor {
void onStart();
Expand Down
16 changes: 16 additions & 0 deletions lib/src/sdk/open_telemetry.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import '../../sdk.dart';

final TracerProvider _noopTracerProvider = TracerProvider();
TracerProvider _tracerProvider = _noopTracerProvider;

void registerGlobalTracerProvider(TracerProvider tracerProvider) {
if (_tracerProvider != _noopTracerProvider) {
throw StateError('A global TracerProvider has already been created. '
'registerGlobalTracerProvider must be called only once before any '
'calls to getter globalTracerProvider.');
}

_tracerProvider = tracerProvider;
}

TracerProvider get globalTracerProvider => _tracerProvider;
3 changes: 1 addition & 2 deletions lib/src/sdk/trace/exporters/collector_exporter.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'package:http/http.dart' as http;

import '../../../api/exporters/span_exporter.dart';
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;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/sdk/trace/exporters/console_exporter.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../../../api/trace/span.dart';

import 'span_exporter.dart';
import '../../../api/exporters/span_exporter.dart';

class ConsoleExporter implements SpanExporter {
var _isShutdown = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/sdk/trace/span.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:fixnum/fixnum.dart';

import '../../api/common/attributes.dart';
import '../../api/span_processors/span_processor.dart';
import '../../api/trace/span.dart' as span_api;
import '../../api/trace/span_status.dart';
import '../../api/trace/tracer.dart';
import '../../sdk/trace/span_context.dart';
import '../common/attributes.dart' as attributes_sdk;
import 'span_id.dart';
import 'span_processors/span_processor.dart';

/// A representation of a single operation within a trace.
class Span implements span_api.Span {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/sdk/trace/span_processors/batch_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'dart:math';

import 'package:logging/logging.dart';

import '../../../api/exporters/span_exporter.dart';
import '../../../api/span_processors/span_processor.dart';
import '../../../api/trace/span.dart';
import '../exporters/span_exporter.dart';
import 'span_processor.dart';

class BatchSpanProcessor implements SpanProcessor {
final _log = Logger('opentelemetry.BatchSpanProcessor');
Expand Down
4 changes: 2 additions & 2 deletions lib/src/sdk/trace/span_processors/simple_processor.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../../../api/exporters/span_exporter.dart';
import '../../../api/span_processors/span_processor.dart';
import '../../../api/trace/span.dart';
import '../exporters/span_exporter.dart';
import 'span_processor.dart';

class SimpleSpanProcessor implements SpanProcessor {
final SpanExporter _exporter;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/sdk/trace/tracer.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '../../../api.dart' as api;
import '../../api/span_processors/span_processor.dart';
import '../common/attributes.dart';
import '../instrumentation_library.dart';
import 'id_generator.dart';
import 'span.dart';
import 'span_context.dart';
import 'span_id.dart';
import 'span_processors/span_processor.dart';
import 'trace_flags.dart';
import 'trace_id.dart';
import 'trace_state.dart';
Expand Down
6 changes: 2 additions & 4 deletions lib/src/sdk/trace/tracer_provider.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import '../../api/instrumentation_library.dart' as version_api;
import '../../api/span_processors/span_processor.dart';
import '../../api/trace/tracer_provider.dart' as api;
import '../instrumentation_library.dart';
import 'exporters/console_exporter.dart';
import 'id_generator.dart';
import 'span_processors/simple_processor.dart';
import 'span_processors/span_processor.dart';
import 'tracer.dart';

/// A registry for creating named [Tracer]s.
Expand All @@ -16,7 +14,7 @@ class TracerProvider implements api.TracerProvider {
IdGenerator _idGenerator;

TracerProvider({List<SpanProcessor> processors, IdGenerator idGenerator}) {
_processors = processors ?? [SimpleSpanProcessor(ConsoleExporter())];
_processors = processors ?? []; // Default to a no-op TracerProvider.
_idGenerator = idGenerator ?? IdGenerator();
// TODO: O11Y-1027: Per spec, a Sampler defaulted to ParentBased(root=AlwaysOn) added here.
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/mocks.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:http/http.dart' as http;
import 'package:mockito/mockito.dart';
import 'package:opentelemetry/src/api/context/context.dart';
import 'package:opentelemetry/src/api/exporters/span_exporter.dart';
import 'package:opentelemetry/src/api/span_processors/span_processor.dart';
import 'package:opentelemetry/src/api/trace/span.dart';
import 'package:opentelemetry/src/sdk/trace/exporters/span_exporter.dart';
import 'package:opentelemetry/src/sdk/trace/span_processors/span_processor.dart';

class MockContext extends Mock implements Context {}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/sdk/span_processors/batch_processor_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:mockito/mockito.dart';
import 'package:opentelemetry/src/api/trace/span.dart';
import 'package:opentelemetry/src/sdk/trace/exporters/span_exporter.dart';
import 'package:opentelemetry/src/api/exporters/span_exporter.dart';
import 'package:opentelemetry/src/sdk/trace/span_processors/batch_processor.dart';
import 'package:test/test.dart';
import '../../mocks.dart';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/sdk/span_processors/simple_processor_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:mockito/mockito.dart';
import 'package:opentelemetry/src/api/trace/span.dart';
import 'package:opentelemetry/src/sdk/trace/exporters/span_exporter.dart';
import 'package:opentelemetry/src/api/exporters/span_exporter.dart';
import 'package:opentelemetry/src/sdk/trace/span_processors/simple_processor.dart';
import 'package:test/test.dart';
import '../../mocks.dart';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/sdk/trace_provider_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:mockito/mockito.dart';
import 'package:opentelemetry/src/sdk/trace/span_processors/span_processor.dart';
import 'package:opentelemetry/src/api/span_processors/span_processor.dart';
import 'package:opentelemetry/src/sdk/trace/tracer_provider.dart';
import 'package:test/test.dart';

Expand Down

0 comments on commit 6fbdadc

Please sign in to comment.