Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions samples/otlptrace/example_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 10 additions & 11 deletions samples/otlptrace/example_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down