|
| 1 | +### Usage |
| 2 | + |
| 3 | +Recommended for traces of moderate and high complexity: |
| 4 | + |
| 5 | +```command |
| 6 | +dima@colima-ahh /c/operator (feat-otel)> docker run --rm --name jaeger \ |
| 7 | + -p 16686:16686 \ |
| 8 | + -p 4317:4317 \ |
| 9 | + -p 4318:4318 \ |
| 10 | + -p 5778:5778 \ |
| 11 | + -p 9411:9411 \ |
| 12 | + jaegertracing/jaeger:2.2.0 |
| 13 | +``` |
| 14 | + |
| 15 | +After which, you should be able to: |
| 16 | +- open http://192.168.107.4:16686/ in your browser |
| 17 | +- select the correct **Service** (`testapp-charm` at current branch state) |
| 18 | +- click Search at the bottom of the form |
| 19 | + |
| 20 | +Note: the `jaeger` container keeps traces in memory, and your Service can't be selected |
| 21 | +until it has sent some data to `jaeger`. |
| 22 | + |
| 23 | +Alternatively, text-based: |
| 24 | + |
| 25 | +```command |
| 26 | +dima@colima-ahh /c/operator (feat-otel)> docker run -it --rm \ |
| 27 | + -v (pwd)/dont-merge/otel-collector-config.yaml:/etc/otel-collector-config.yaml \ |
| 28 | + -p 4317:4317 \ |
| 29 | + -p 4318:4318 \ |
| 30 | + otel/opentelemetry-collector:latest \ |
| 31 | + --config=/etc/otel-collector-config.yaml |
| 32 | +``` |
| 33 | + |
| 34 | +and then |
| 35 | + |
| 36 | +```command |
| 37 | +dima@colima-ahh /c/operator (feat-otel)> uv venv --seed .ahh-venv |
| 38 | +Using CPython 3.13.0 |
| 39 | +Creating virtual environment with seed packages at: .ahh-venv |
| 40 | + |
| 41 | +dima@colima-ahh /c/operator (feat-otel)> . .ahh-venv/bin/activate.fish |
| 42 | +(.ahh-venv) dima@colima-ahh /c/operator (feat-otel)> |
| 43 | + |
| 44 | +(.ahh-venv) dima@colima-ahh /c/operator (feat-otel)> uv pip install -e .[tracing] -U |
| 45 | +Using Python 3.13.0 environment at .ahh-venv |
| 46 | +Resolved 21 packages in 907ms |
| 47 | +Prepared 18 packages in 72ms |
| 48 | +... |
| 49 | + |
| 50 | +(.ahh-venv) dima@colima-ahh /c/operator (feat-otel)> python dont-merge/send-traces.py |
| 51 | +Span created and exported to the collector! |
| 52 | +``` |
| 53 | + |
| 54 | +### Hacking |
| 55 | + |
| 56 | +Or, trying to run code outside of a charm. |
| 57 | + |
| 58 | +Somehow I'm not getting anything, because the `juju-log` hook tool is missing. |
| 59 | + |
| 60 | +Let's fix that. |
| 61 | + |
| 62 | +```command |
| 63 | +> ln -s (which echo) juju-log |
| 64 | +``` |
| 65 | + |
| 66 | +Generate some tracing data: |
| 67 | + |
| 68 | +```command |
| 69 | +(venv) > JUJU_UNIT_NAME=testapp/42 JUJU_CHARM_DIR=dont-merge/ PATH=$PATH:. JUJU_VERSION=3.5.4 ./dont-merge/start |
| 70 | +``` |
| 71 | + |
| 72 | +OTEL collector debug output would look like this: |
| 73 | + |
| 74 | +``` |
| 75 | +2025-01-15T08:46:23.229Z info Traces {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 1, "spans": 1} |
| 76 | +2025-01-15T08:46:23.229Z info ResourceSpans #0 |
| 77 | +Resource SchemaURL: |
| 78 | +Resource attributes: |
| 79 | + -> telemetry.sdk.language: Str(python) |
| 80 | + -> telemetry.sdk.name: Str(opentelemetry) |
| 81 | + -> telemetry.sdk.version: Str(1.29.0) |
| 82 | + -> service.name: Str(testapp-charm) |
| 83 | + -> compose_service: Str(testapp-charm) |
| 84 | + -> charm_type: Str(CharmBase) |
| 85 | + -> juju_unit: Str(testapp/42) |
| 86 | + -> juju_application: Str(testapp) |
| 87 | + -> juju_model: Str() |
| 88 | + -> juju_model_uuid: Str() |
| 89 | +ScopeSpans #0 |
| 90 | +ScopeSpans SchemaURL: |
| 91 | +InstrumentationScope ops |
| 92 | +Span #0 |
| 93 | + Trace ID : 8c3f292c89f29c59f1b37fe59ba0abbc |
| 94 | + Parent ID : |
| 95 | + ID : e0253a03ef694a4f |
| 96 | + Name : ops.main |
| 97 | + Kind : Internal |
| 98 | + Start time : 2025-01-15 08:46:23.175916835 +0000 UTC |
| 99 | + End time : 2025-01-15 08:46:23.182329655 +0000 UTC |
| 100 | + Status code : Error |
| 101 | + Status message : RuntimeError: command not found: is-leader |
| 102 | +Events: |
| 103 | +SpanEvent #0 |
| 104 | + -> Name: exception |
| 105 | + -> Timestamp: 2025-01-15 08:46:23.182316071 +0000 UTC |
| 106 | + -> DroppedAttributesCount: 0 |
| 107 | + -> Attributes:: |
| 108 | + -> exception.type: Str(RuntimeError) |
| 109 | + -> exception.message: Str(command not found: is-leader) |
| 110 | + -> exception.stacktrace: Str(Traceback (most recent call last): |
| 111 | + ... |
| 112 | + -> exception.escaped: Str(False) |
| 113 | + {"kind": "exporter", "data_type": "traces", "name": "debug"} |
| 114 | +``` |
0 commit comments