Skip to content

Commit

Permalink
reordered imports
Browse files Browse the repository at this point in the history
  • Loading branch information
PietroPasotti committed Feb 6, 2025
1 parent 3bd31c9 commit 890131b
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
```python
# import the necessary charm libs
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer, charm_tracing_config
from charms.tempo_coordinator_k8s.v0.tracing import (
TracingEndpointRequirer,
charm_tracing_config,
)
from charms.tempo_coordinator_k8s.v0.charm_tracing import charm_tracing
# decorate your charm class with charm_tracing:
@charm_tracing(
# forward-declare the instance attributes that the instrumentor will look up to obtain the
# tempo endpoint and server certificate
tracing_endpoint="tracing_endpoint",
server_cert="server_cert"
server_cert="server_cert",
)
class MyCharm(CharmBase):
_path_to_cert = "/path/to/cert.crt"
Expand All @@ -37,10 +41,12 @@ class MyCharm(CharmBase):
# If you do support TLS, you'll need to make sure that the server cert is copied to this location
# and kept up to date so the instrumentor can use it.
def __init__(self, ...):
...
self.tracing = TracingEndpointRequirer(self, ...)
self.tracing_endpoint, self.server_cert = charm_tracing_config(self.tracing, self._path_to_cert)
def __init__(self, framework):
# ...
self.tracing = TracingEndpointRequirer(self)
self.tracing_endpoint, self.server_cert = charm_tracing_config(
self.tracing, self._path_to_cert
)
```
# Detailed usage
Expand Down Expand Up @@ -225,12 +231,6 @@ def my_tracing_endpoint(self) -> Optional[str]:
3) If you were passing a certificate (str) using `server_cert`, you need to change it to
provide an *absolute* path to the certificate file instead.
"""
import typing

from opentelemetry.exporter.otlp.proto.common._internal.trace_encoder import (
encode_spans,
)
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter


def _remove_stale_otel_sdk_packages():
Expand Down Expand Up @@ -285,12 +285,14 @@ def _remove_stale_otel_sdk_packages():
# apply hacky patch to remove stale opentelemetry sdk packages on upgrade-charm.
# it could be trouble if someone ever decides to implement their own tracer parallel to
# ours and before the charm has inited. We assume they won't.
# !!IMPORTANT!! keep all otlp imports UNDER this call.
_remove_stale_otel_sdk_packages()

import functools
import inspect
import logging
import os
import typing
from contextlib import contextmanager
from contextvars import Context, ContextVar, copy_context
from pathlib import Path
Expand All @@ -309,6 +311,9 @@ def _remove_stale_otel_sdk_packages():

import opentelemetry
import ops
from opentelemetry.exporter.otlp.proto.common._internal.trace_encoder import (
encode_spans,
)
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import ReadableSpan, Span, TracerProvider
Expand All @@ -317,6 +322,7 @@ def _remove_stale_otel_sdk_packages():
SpanExporter,
SpanExportResult,
)
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.trace import INVALID_SPAN, Tracer
from opentelemetry.trace import get_current_span as otlp_get_current_span
from opentelemetry.trace import (
Expand All @@ -337,7 +343,7 @@ def _remove_stale_otel_sdk_packages():
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version

LIBPATCH = 4
LIBPATCH = 5

PYDEPS = ["opentelemetry-exporter-otlp-proto-http==1.21.0"]

Expand Down Expand Up @@ -365,7 +371,7 @@ def _remove_stale_otel_sdk_packages():
BUFFER_DEFAULT_MAX_EVENT_HISTORY_LENGTH = 100
_MiB_TO_B = 2**20 # megabyte to byte conversion rate
_OTLP_SPAN_EXPORTER_TIMEOUT = 1
"""Timeout in seconds that the OTLP span exporter has to push traces to the backend."""
# Timeout in seconds that the OTLP span exporter has to push traces to the backend.


class _Buffer:
Expand Down

0 comments on commit 890131b

Please sign in to comment.