@@ -6,6 +6,7 @@ import 'dart:async';
66import 'package:meta/meta.dart' ;
77
88import '../../api.dart' as api;
9+ import '../../src/sdk/trace/tracer.dart' as sdk show Tracer;
910import '../experimental_api.dart' ;
1011import 'propagation/noop_text_map_propagator.dart' ;
1112import 'trace/noop_tracer_provider.dart' ;
@@ -102,12 +103,23 @@ Future<T> trace<T>(String name, Future<T> Function() fn,
102103 context ?? = api.Context .current;
103104 tracer ?? = _tracerProvider.getTracer ('opentelemetry-dart' );
104105
105- final span = tracer.startSpan (name,
106- // TODO: use start span option `newRoot` instead
107- context: newRoot ? api.Context .root : context,
108- attributes: spanAttributes,
109- kind: spanKind,
110- links: spanLinks);
106+ // TODO: use start span option `newRoot` instead
107+ var span;
108+ if (tracer is sdk.Tracer ) {
109+ span = tracer.startSpan (name,
110+ context: context,
111+ attributes: spanAttributes,
112+ kind: spanKind,
113+ links: spanLinks,
114+ newRoot: newRoot);
115+ } else {
116+ span = tracer.startSpan (name,
117+ context: newRoot ? api.Context .root : context,
118+ attributes: spanAttributes,
119+ kind: spanKind,
120+ links: spanLinks);
121+ }
122+
111123 try {
112124 return await Zone .current.fork ().run (() {
113125 final token = api.Context .attach (api.contextWithSpan (context! , span));
@@ -139,12 +151,23 @@ T traceSync<T>(String name, T Function() fn,
139151 context ?? = api.Context .current;
140152 tracer ?? = _tracerProvider.getTracer ('opentelemetry-dart' );
141153
142- final span = tracer.startSpan (name,
143- // TODO: use start span option `newRoot` instead
144- context: newRoot ? api.Context .root : context,
145- attributes: spanAttributes,
146- kind: spanKind,
147- links: spanLinks);
154+ // TODO: use start span option `newRoot` instead
155+ var span;
156+ if (tracer is sdk.Tracer ) {
157+ span = tracer.startSpan (name,
158+ context: context,
159+ attributes: spanAttributes,
160+ kind: spanKind,
161+ links: spanLinks,
162+ newRoot: newRoot);
163+ } else {
164+ span = tracer.startSpan (name,
165+ context: newRoot ? api.Context .root : context,
166+ attributes: spanAttributes,
167+ kind: spanKind,
168+ links: spanLinks);
169+ }
170+
148171 try {
149172 return Zone .current.fork ().run (() {
150173 final token = api.Context .attach (api.contextWithSpan (context! , span));
0 commit comments