2020import com .google .cloud .bigquery .BigQuery ;
2121import com .google .cloud .bigquery .BigQueryOptions ;
2222import com .google .cloud .bigquery .Dataset ;
23- import com .google .cloud .bigquery .DatasetId ;
2423import com .google .cloud .bigquery .DatasetInfo ;
2524import io .opentelemetry .api .OpenTelemetry ;
2625import io .opentelemetry .api .common .AttributeKey ;
2726import io .opentelemetry .api .trace .Span ;
2827import io .opentelemetry .api .trace .Tracer ;
2928import io .opentelemetry .context .Scope ;
30- import java .util .HashMap ;
31- import java .util .Map ;
32- import java .util .Collection ;
3329import io .opentelemetry .sdk .OpenTelemetrySdk ;
3430import io .opentelemetry .sdk .common .CompletableResultCode ;
3531import io .opentelemetry .sdk .trace .SdkTracerProvider ;
3632import io .opentelemetry .sdk .trace .data .SpanData ;
3733import io .opentelemetry .sdk .trace .export .SimpleSpanProcessor ;
3834import io .opentelemetry .sdk .trace .samplers .Sampler ;
35+ import java .util .Collection ;
36+ import java .util .HashMap ;
37+ import java .util .Map ;
3938
4039public class EnableOpenTelemetryTracingWithParentSpan {
4140
@@ -47,7 +46,8 @@ public class EnableOpenTelemetryTracingWithParentSpan {
4746
4847 // Create a SpanExporter to determine how to handle captured Span data.
4948 // See more at https://opentelemetry.io/docs/languages/java/sdk/#spanexporter
50- private static class SampleSpanExporter implements io .opentelemetry .sdk .trace .export .SpanExporter {
49+ private static class SampleSpanExporter
50+ implements io .opentelemetry .sdk .trace .export .SpanExporter {
5151 @ Override
5252 public CompletableResultCode export (Collection <SpanData > collection ) {
5353 // Export data. This data can be sent out of process via netowork calls, though
@@ -92,9 +92,8 @@ public static void enableOpenTelemetryWithParentSpan(String tracerName) {
9292 .build ();
9393
9494 // Create global OpenTelemetry instance using the TracerProvider.
95- OpenTelemetry otel = OpenTelemetrySdk .builder ()
96- .setTracerProvider (tracerProvider )
97- .buildAndRegisterGlobal ();
95+ OpenTelemetry otel =
96+ OpenTelemetrySdk .builder ().setTracerProvider (tracerProvider ).buildAndRegisterGlobal ();
9897
9998 // Create Tracer instance from the global OpenTelemetry object. Tracers are used to create
10099 // Spans. There can be multiple Tracers in a global OpenTelemetry instance.
@@ -126,17 +125,26 @@ public static void enableOpenTelemetryWithParentSpan(String tracerName) {
126125 // finally block ensures that Spans are cleaned up properly.
127126 parentSpan .end ();
128127
129- if (OTEL_ATTRIBUTES .get ("Sample Parent Span" ).get (AttributeKey .stringKey ("sample-parent-attribute" )) == "sample-parent-value" ) {
128+ if (OTEL_ATTRIBUTES
129+ .get ("Sample Parent Span" )
130+ .get (AttributeKey .stringKey ("sample-parent-attribute" ))
131+ == "sample-parent-value" ) {
130132 System .out .println ("Parent Span was captured!" );
131133 } else {
132134 System .out .println ("Parent Span was not captured!" );
133135 }
134- if (OTEL_ATTRIBUTES .get ("Sample Child Span" ).get (AttributeKey .stringKey ("sample-child-attribute" )) == "sample-child-value" ) {
136+ if (OTEL_ATTRIBUTES
137+ .get ("Sample Child Span" )
138+ .get (AttributeKey .stringKey ("sample-child-attribute" ))
139+ == "sample-child-value" ) {
135140 System .out .println ("Child Span was captured!" );
136141 } else {
137142 System .out .println ("Child Span was not captured!" );
138143 }
139- if (OTEL_ATTRIBUTES .get ("Sample Child Span" ).get (AttributeKey .stringKey ("sample-child-attribute" )) == "sample-child-value" ) {
144+ if (OTEL_ATTRIBUTES
145+ .get ("Sample Child Span" )
146+ .get (AttributeKey .stringKey ("sample-child-attribute" ))
147+ == "sample-child-value" ) {
140148 System .out .println ("Child Span was captured!" );
141149 } else {
142150 System .out .println ("Child Span was not captured!" );
@@ -158,11 +166,9 @@ public static void createDataset(BigQuery bigquery, Tracer tracer, String datase
158166 .setAttribute ("sample-child-attribute" , "sample-child-value" )
159167 .startSpan ();
160168
161- DatasetInfo info =
162- DatasetInfo .newBuilder (datasetId )
163- .build ();
169+ DatasetInfo info = DatasetInfo .newBuilder (datasetId ).build ();
164170
165171 Dataset dataset = bigquery .create (info );
166172 }
167173}
168- // [END bigquery_enable_otel_tracing_with_parent_span]
174+ // [END bigquery_enable_otel_tracing_with_parent_span]
0 commit comments