Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions samples/otlptrace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ gcloud auth application-default login

#### Run the Sample
```sh
# export necessary OTEL environment variables
# export necessary OTEL environment variable
export OTEL_RESOURCE_ATTRIBUTES="gcp.project_id=<project-id>"
export OTEL_EXPORTER_OTLP_ENDPOINT=<endpoint>

# from the samples/otlptrace repository
python3 example_grpc.py
Expand Down
11 changes: 7 additions & 4 deletions samples/otlptrace/example_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@
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,
endpoint="https://telemetry.googleapis.com:443/v1/traces",
)
)
trace_provider.add_span_processor(processor)
trace.set_tracer_provider(trace_provider)
tracer = trace.get_tracer("my.tracer.name")
Expand Down
21 changes: 11 additions & 10 deletions samples/otlptrace/example_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@
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))
trace_provider = TracerProvider(resource=Resource.create(attributes={SERVICE_NAME: "otlp-gcp-http-sample"}))
processor = BatchSpanProcessor(
OTLPSpanExporter(
headers={
"x-goog-user-project": credentials.quota_project_id,
},
session=AuthorizedSession(credentials),
endpoint="https://telemetry.googleapis.com:443/v1/traces",
)
)
trace_provider.add_span_processor(processor)
trace.set_tracer_provider(trace_provider)
tracer = trace.get_tracer("my.tracer.name")
Expand Down