diff --git a/samples/otlptrace/example_grpc.py b/samples/otlptrace/example_grpc.py index 5a0be5b1..80980f52 100644 --- a/samples/otlptrace/example_grpc.py +++ b/samples/otlptrace/example_grpc.py @@ -32,20 +32,22 @@ This is a sample script that exports OTLP traces encoded as protobufs via gRPC. """ -credentials, project_id = google.auth.default() +credentials, _ = google.auth.default() request = google.auth.transport.requests.Request() resource = Resource.create(attributes={SERVICE_NAME: "otlp-gcp-grpc-sample"}) -auth_metadata_plugin = AuthMetadataPlugin( - credentials=credentials, request=request -) +auth_metadata_plugin = AuthMetadataPlugin(credentials=credentials, request=request) channel_creds = grpc.composite_channel_credentials( grpc.ssl_channel_credentials(), grpc.metadata_call_credentials(auth_metadata_plugin), ) trace_provider = TracerProvider(resource=resource) -processor = BatchSpanProcessor(OTLPSpanExporter(credentials=channel_creds)) +processor = BatchSpanProcessor( + OTLPSpanExporter( + credentials=channel_creds, + ) +) trace_provider.add_span_processor(processor) trace.set_tracer_provider(trace_provider) tracer = trace.get_tracer("my.tracer.name") diff --git a/samples/otlptrace/example_http.py b/samples/otlptrace/example_http.py index 854f7e20..a613beed 100644 --- a/samples/otlptrace/example_http.py +++ b/samples/otlptrace/example_http.py @@ -19,21 +19,20 @@ from opentelemetry.exporter.otlp.proto.http.trace_exporter import ( OTLPSpanExporter, ) +from google.auth.transport.requests import AuthorizedSession from opentelemetry.sdk.resources import SERVICE_NAME, Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor -credentials, project_id = google.auth.default() -request = google.auth.transport.requests.Request() -credentials.refresh(request) -req_headers = { - "x-goog-user-project": credentials.quota_project_id, - "Authorization": "Bearer " + credentials.token, -} -resource = Resource.create(attributes={SERVICE_NAME: "otlp-gcp-http-sample"}) - -trace_provider = TracerProvider(resource=resource) -processor = BatchSpanProcessor(OTLPSpanExporter(headers=req_headers)) +credentials, _ = google.auth.default() +trace_provider = TracerProvider( + resource=Resource.create(attributes={SERVICE_NAME: "otlp-gcp-http-sample"}) +) +processor = BatchSpanProcessor( + OTLPSpanExporter( + session=AuthorizedSession(credentials), + ) +) trace_provider.add_span_processor(processor) trace.set_tracer_provider(trace_provider) tracer = trace.get_tracer("my.tracer.name")