Hello Everyone,
I am using following code to send traces to grafana cloud instance
import base64
import json
import os
import time
import traceback
from datetime import datetime
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import \
OTLPSpanExporter
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from pydantic import BaseModel
from structlog.contextvars import bound_contextvars
def create_span_exporter_for_tempo():
resource = Resource(attributes={
"service.name": "Service"
})
username = "<instance-id>"
password = "<api key / cloud policy token>"
headers = {"Authorization": f"Basic {base64.b64encode(f'{username}:{password}'.encode('ascii')).decode('ascii')}"}
tempo_exporter = OTLPSpanExporter(
endpoint="https://otlp-gateway-prod-us-east-0.grafana.net/otlp/v1/traces",
headers=headers,
)
trace.set_tracer_provider(TracerProvider(resource=resource))
tracer = trace.get_tracer(__name__)
# Create a span processor and add the exporter to it
span_processor = BatchSpanProcessor(tempo_exporter)
trace.get_tracer_provider().add_span_processor(span_processor)
with tracer.start_as_current_span("test") as span:
print("test!")
span.set_attribute("check", "works")
print("Executing tracing ...")
create_span_exporter_for_tempo()
print("Executed tracing ...")
I tried cloud policy token as well as API key but none of them worked.
P.S. Cloud token has right permissions for sending traces.
Is there anything changed recently ?
As I have created this account today only.