Skip to content

Commit 60ad054

Browse files
[DPE-5312] Pull tracing charm libs from tempo_coordinator_k8s instead (#180)
## Issue We are unable to relay traces through grafana-agent due to canonical/grafana-agent-operator#195. However, in the meantime, we would like to update the charm tracing libs as they now reside in `tempo_coordinator_k8s` ## Solution Update location of charm tracing libs
1 parent 2eefed0 commit 60ad054

File tree

6 files changed

+48
-43
lines changed

6 files changed

+48
-43
lines changed

lib/charms/tempo_k8s/v1/charm_tracing.py renamed to lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
# Quickstart
1313
Fetch the following charm libs (and ensure the minimum version/revision numbers are satisfied):
1414
15-
charmcraft fetch-lib charms.tempo_k8s.v2.tracing # >= 1.10
16-
charmcraft fetch-lib charms.tempo_k8s.v1.charm_tracing # >= 2.7
15+
charmcraft fetch-lib charms.tempo_coordinator_k8s.v0.tracing # >= 1.10
16+
charmcraft fetch-lib charms.tempo_coordinator_k8s.v0.charm_tracing # >= 2.7
1717
1818
Then edit your charm code to include:
1919
2020
```python
2121
# import the necessary charm libs
22-
from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer, charm_tracing_config
23-
from charms.tempo_k8s.v1.charm_tracing import charm_tracing
22+
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer, charm_tracing_config
23+
from charms.tempo_coordinator_k8s.v0.charm_tracing import charm_tracing
2424
2525
# decorate your charm class with charm_tracing:
2626
@charm_tracing(
@@ -51,7 +51,7 @@ def __init__(self, ...):
5151
5252
2) add to your charm a "my_tracing_endpoint" (you can name this attribute whatever you like)
5353
**property**, **method** or **instance attribute** that returns an otlp http/https endpoint url.
54-
If you are using the ``charms.tempo_k8s.v2.tracing.TracingEndpointRequirer`` as
54+
If you are using the ``charms.tempo_coordinator_k8s.v0.tracing.TracingEndpointRequirer`` as
5555
``self.tracing = TracingEndpointRequirer(self)``, the implementation could be:
5656
5757
```
@@ -80,7 +80,7 @@ def my_tracing_endpoint(self) -> Optional[str]:
8080
8181
For example:
8282
```
83-
from charms.tempo_k8s.v1.charm_tracing import trace_charm
83+
from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
8484
@trace_charm(
8585
tracing_endpoint="my_tracing_endpoint",
8686
server_cert="_server_cert"
@@ -129,7 +129,7 @@ def get_tracer(self) -> opentelemetry.trace.Tracer:
129129
For example:
130130
131131
```
132-
from charms.tempo_k8s.v0.charm_tracing import trace_charm
132+
from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
133133
134134
@trace_charm(
135135
tracing_endpoint="my_tracing_endpoint",
@@ -150,7 +150,7 @@ def my_tracing_endpoint(self) -> Optional[str]:
150150
needs to be replaced with:
151151
152152
```
153-
from charms.tempo_k8s.v1.charm_tracing import trace_charm
153+
from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
154154
155155
@trace_charm(
156156
tracing_endpoint="my_tracing_endpoint",
@@ -249,28 +249,27 @@ def _remove_stale_otel_sdk_packages():
249249
from opentelemetry.sdk.resources import Resource
250250
from opentelemetry.sdk.trace import Span, TracerProvider
251251
from opentelemetry.sdk.trace.export import BatchSpanProcessor
252+
from opentelemetry.trace import INVALID_SPAN, Tracer
253+
from opentelemetry.trace import get_current_span as otlp_get_current_span
252254
from opentelemetry.trace import (
253-
INVALID_SPAN,
254-
Tracer,
255255
get_tracer,
256256
get_tracer_provider,
257257
set_span_in_context,
258258
set_tracer_provider,
259259
)
260-
from opentelemetry.trace import get_current_span as otlp_get_current_span
261260
from ops.charm import CharmBase
262261
from ops.framework import Framework
263262

264263
# The unique Charmhub library identifier, never change it
265-
LIBID = "cb1705dcd1a14ca09b2e60187d1215c7"
264+
LIBID = "01780f1e588c42c3976d26780fdf9b89"
266265

267266
# Increment this major API version when introducing breaking changes
268-
LIBAPI = 1
267+
LIBAPI = 0
269268

270269
# Increment this PATCH version before using `charmcraft publish-lib` or reset
271270
# to 0 if you are raising the major API version
272271

273-
LIBPATCH = 15
272+
LIBPATCH = 2
274273

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

@@ -332,7 +331,7 @@ def _get_tracer() -> Optional[Tracer]:
332331
return tracer.get()
333332
except LookupError:
334333
# fallback: this course-corrects for a user error where charm_tracing symbols are imported
335-
# from different paths (typically charms.tempo_k8s... and lib.charms.tempo_k8s...)
334+
# from different paths (typically charms.tempo_coordinator_k8s... and lib.charms.tempo_coordinator_k8s...)
336335
try:
337336
ctx: Context = copy_context()
338337
if context_tracer := _get_tracer_from_context(ctx):
@@ -372,10 +371,6 @@ class UntraceableObjectError(TracingError):
372371
"""Raised when an object you're attempting to instrument cannot be autoinstrumented."""
373372

374373

375-
class TLSError(TracingError):
376-
"""Raised when the tracing endpoint is https but we don't have a cert yet."""
377-
378-
379374
def _get_tracing_endpoint(
380375
tracing_endpoint_attr: str,
381376
charm_instance: object,
@@ -485,10 +480,15 @@ def wrap_init(self: CharmBase, framework: Framework, *args, **kwargs):
485480
)
486481

487482
if tracing_endpoint.startswith("https://") and not server_cert:
488-
raise TLSError(
483+
logger.error(
489484
"Tracing endpoint is https, but no server_cert has been passed."
490-
"Please point @trace_charm to a `server_cert` attr."
485+
"Please point @trace_charm to a `server_cert` attr. "
486+
"This might also mean that the tracing provider is related to a "
487+
"certificates provider, but this application is not (yet). "
488+
"In that case, you might just have to wait a bit for the certificates "
489+
"integration to settle. "
491490
)
491+
return
492492

493493
exporter = OTLPSpanExporter(
494494
endpoint=tracing_endpoint,
@@ -562,8 +562,8 @@ def trace_charm(
562562
method calls on instances of this class.
563563
564564
Usage:
565-
>>> from charms.tempo_k8s.v1.charm_tracing import trace_charm
566-
>>> from charms.tempo_k8s.v1.tracing import TracingEndpointRequirer
565+
>>> from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
566+
>>> from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer
567567
>>> from ops import CharmBase
568568
>>>
569569
>>> @trace_charm(
@@ -626,7 +626,7 @@ def _autoinstrument(
626626
627627
Usage:
628628
629-
>>> from charms.tempo_k8s.v1.charm_tracing import _autoinstrument
629+
>>> from charms.tempo_coordinator_k8s.v0.charm_tracing import _autoinstrument
630630
>>> from ops.main import main
631631
>>> _autoinstrument(
632632
>>> MyCharm,

lib/charms/tempo_k8s/v2/tracing.py renamed to lib/charms/tempo_coordinator_k8s/v0/tracing.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
This relation must use the `tracing` interface.
1717
The `TracingEndpointRequirer` object may be instantiated as follows
1818
19-
from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer
19+
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer
2020
2121
def __init__(self, *args):
2222
super().__init__(*args)
@@ -58,7 +58,7 @@ def __init__(self, *args):
5858
For example a Tempo charm may instantiate the `TracingEndpointProvider` in its constructor as
5959
follows
6060
61-
from charms.tempo_k8s.v2.tracing import TracingEndpointProvider
61+
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointProvider
6262
6363
def __init__(self, *args):
6464
super().__init__(*args)
@@ -100,14 +100,14 @@ def __init__(self, *args):
100100
from pydantic import BaseModel, Field
101101

102102
# The unique Charmhub library identifier, never change it
103-
LIBID = "12977e9aa0b34367903d8afeb8c3d85d"
103+
LIBID = "d2f02b1f8d1244b5989fd55bc3a28943"
104104

105105
# Increment this major API version when introducing breaking changes
106-
LIBAPI = 2
106+
LIBAPI = 0
107107

108108
# Increment this PATCH version before using `charmcraft publish-lib` or reset
109109
# to 0 if you are raising the major API version
110-
LIBPATCH = 10
110+
LIBPATCH = 2
111111

112112
PYDEPS = ["pydantic"]
113113

@@ -947,8 +947,8 @@ def charm_tracing_config(
947947
948948
Usage:
949949
If you are using charm_tracing >= v1.9:
950-
>>> from lib.charms.tempo_k8s.v1.charm_tracing import trace_charm
951-
>>> from lib.charms.tempo_k8s.v2.tracing import charm_tracing_config
950+
>>> from lib.charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
951+
>>> from lib.charms.tempo_coordinator_k8s.v0.tracing import charm_tracing_config
952952
>>> @trace_charm(tracing_endpoint="my_endpoint", cert_path="cert_path")
953953
>>> class MyCharm(...):
954954
>>> _cert_path = "/path/to/cert/on/charm/container.crt"
@@ -958,8 +958,8 @@ def charm_tracing_config(
958958
... self.tracing, self._cert_path)
959959
960960
If you are using charm_tracing < v1.9:
961-
>>> from lib.charms.tempo_k8s.v1.charm_tracing import trace_charm
962-
>>> from lib.charms.tempo_k8s.v2.tracing import charm_tracing_config
961+
>>> from lib.charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
962+
>>> from lib.charms.tempo_coordinator_k8s.v0.tracing import charm_tracing_config
963963
>>> @trace_charm(tracing_endpoint="my_endpoint", cert_path="cert_path")
964964
>>> class MyCharm(...):
965965
>>> _cert_path = "/path/to/cert/on/charm/container.crt"
@@ -985,11 +985,16 @@ def charm_tracing_config(
985985
is_https = endpoint.startswith("https://")
986986

987987
if is_https:
988-
if cert_path is None:
989-
raise TracingError("Cannot send traces to an https endpoint without a certificate.")
990-
elif not Path(cert_path).exists():
991-
# if endpoint is https BUT we don't have a server_cert yet:
992-
# disable charm tracing until we do to prevent tls errors
988+
if cert_path is None or not Path(cert_path).exists():
989+
# disable charm tracing until we obtain a cert to prevent tls errors
990+
logger.error(
991+
"Tracing endpoint is https, but no server_cert has been passed."
992+
"Please point @trace_charm to a `server_cert` attr. "
993+
"This might also mean that the tracing provider is related to a "
994+
"certificates provider, but this application is not (yet). "
995+
"In that case, you might just have to wait a bit for the certificates "
996+
"integration to settle. "
997+
)
993998
return None, None
994999
return endpoint, str(cert_path)
9951000
else:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ ops = ">=2.0.0"
2525
cryptography = ">=42.0.5"
2626
jsonschema = "*"
2727
# grafana_agent/v0/cos_agent.py
28-
# tempo_k8s/v2/tracing.py supports both pydantic v1 and v2
28+
# tempo_coordinator_k8s/v/tracing.py supports both pydantic v1 and v2
2929
pydantic = "<2"
3030
cosl = "*"
31-
# tempo_k8s/v1/charm_tracing.py
31+
# tempo_coordinator_k8s/v0/charm_tracing.py
3232
opentelemetry-exporter-otlp-proto-http = "1.21.0"
3333

3434
[tool.poetry.group.format]

src/abstract_charm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import typing
99

1010
import ops
11-
from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer
11+
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer
1212

1313
import container
1414
import lifecycle

src/machine_charm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import ops
1414
import tenacity
15-
from charms.tempo_k8s.v1.charm_tracing import trace_charm
15+
from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
1616

1717
import abstract_charm
1818
import logrotate

tests/unit/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import ops
77
import pytest
8-
from charms.tempo_k8s.v1.charm_tracing import charm_tracing_disabled
8+
from charms.tempo_coordinator_k8s.v0.charm_tracing import charm_tracing_disabled
99
from pytest_mock import MockerFixture
1010

1111
import snap

0 commit comments

Comments
 (0)