Skip to content

Commit

Permalink
Rename example.py -> example_http.py (#317)
Browse files Browse the repository at this point in the history
* Rename example.py -> example-http.py

* Add OTel resource to TracerProvider

* udpate example-http.py to example_http.py

* Trigger status checks
  • Loading branch information
psx95 authored May 1, 2024
1 parent 6b7211d commit f84ece2
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import google.auth
import google.auth.transport.requests
from google.auth.transport.requests import AuthorizedSession
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
OTLPSpanExporter,
Expand All @@ -31,16 +30,19 @@
"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()
trace_provider = TracerProvider(resource=resource)
processor = BatchSpanProcessor(OTLPSpanExporter(headers=req_headers))
trace_provider.add_span_processor(processor)
trace.set_tracer_provider(trace_provider)
tracer = trace.get_tracer("my.tracer.name")


def do_work():
with tracer.start_as_current_span("span-name") as span:
with tracer.start_as_current_span("span-http") as span:
# do some work that 'span' will track
print("doing some work...")
# When the 'with' block goes out of scope, 'span' is closed for you
Expand Down

0 comments on commit f84ece2

Please sign in to comment.