Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python/iot3: extend OpenTelemetry attributes #178

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ymorin-orange
Copy link
Member

Features;

  • Extend OpenTelemetry attributes
    • common, generic attribute iot3.core.sdk_language
    • MQTT attributes iot3.core.mqtt.payload_size and iot3.core.mqtt.topic

How to test

  1. Prepare an OpenTelemetry collector on localhost:
    $ docker container run \
        --rm \
        -p 16686:16686 \
        -p 4318:4318 \
        jaegertracing/all-in-one:1.58
    
    then open a browser on the Jaegger UI:
    http://localhost:16686/
    
  2. Start an MQTT client:
    $ mosquitto_sub \
        -h test.mosquitto.org -p 1883 \
        -t 'test/+/iot3/#' \
        -F '%j' \
    | jq -C .
    
  3. Test IoT3 Core SDK:
    1. start an environment with python 3.11:
      $ docker container run \
          --rm \
          -ti \
          --network host \
          -e http_proxy \
          -e https_proxy \
          -e no_proxy \
          --user $(id -u):$(id -u) \
          --mount type=bind,source=$(pwd),destination=$(pwd) \
          --workdir $(pwd) \
          --entrypoint /bin/bash \
          python:3.11.9-slim-bookworm
    2. create a /venv/ in a writable location, and activate it:
      (docker) python3 -m venv /tmp/iot3
      (docker) . /tmp/iot3/bin/activate
    3. install the IoT3 Core SDK (notice the trailing dot .):
      (docker) pip3 --disable-pip-version-check install .
    4. Run the OpenTelemetry-only test:
      (docker) ./tests/test-iot3-core-otel
      then, in Jaegger, search for the traces for the test-service service.
    5. Run the MQTT with OpenTelemetry test:
      (docker) ./tests/test-iot3-core-all
      then, in Jaegger, search for the traces for the test-service service.
    6. Run the simple API test:
      (docker) ./tests/test-iot3-core
      then, in Jaegger, search for the traces for the my-service service.

Expected results:

  1. The Jaegger UI is displayed in your browser
  2. The mosquitto lient is running
  3. The IoT3 Core SDK works;
    1. the docker container runs
    2. the python /venv/ is created and activated
    3. the IoT3 Core SDK is installed
    4. the Jaegger UI finds two traces:
      • one with 6 spans, of which the last one is in error, reporting /Some failure/
      • one with a single span, which has a link to the root span of the first trace, above
      • all spans have an attribute:
        • iot3.core.sdk_language=python
    5. the MQTT message is dumped by /mosquitto_sub/:
      {
        "tst": "2024-10-21T08:58:15.206188Z+0200",
        "topic": "test/5c2a8ef897cf0abb1941cea0fd184b7e/iot3/passed",
        "qos": 0,
        "retain": 0,
        "payloadlen": 6,
        "properties": {
          "user-properties": {
            "traceparent": "00-9c39cc87f7098ec82542cdf38617cef9-f8b69d89c0029e03-00"
          }
        },
        "payload": "passed"
      }
      then Jaegger UI finds three new traces, all with a single span:
      • the first is for the failed publish, and has a span:
        • of kind producer
        • with attributes:
          • iot3.core.sdk_language=python
          • iot3.core.mqtt.payload_size=7
          • iot3.core.mqtt.topic=foo/bar/dropped
        • with an error status reporting /The client is not currently connected./
      • the second is for the sucessful publish, and has a span:
        • of kind producer
        • with attributes:
          • iot3.core.sdk_language=python
          • iot3.core.mqtt.payload_size=6
          • iot3.core.mqtt.topic=foo/bar/passed
        • with an unset status
      • the third is for the receive, and has a span:
        • of kind consumer
        • with attributes:
          • iot3.core.sdk_language=python
          • iot3.core.mqtt.payload_size=6
          • iot3.core.mqtt.topic=foo/bar/passed
        • with an unset status
        • with a link to the span of the second trace, above
    6. the results are similar to those of step 5, above

The publish/receive actions are matching the producer/consumer span
kind, so the action attribute is superfluous.

Besides, the attribute was in the 'test' namespace, so it was not
supposed to linger too long.

Drop it.

Signed-off-by: Yann E. MORIN <[email protected]>
The span attribute with the MQTT topic is no longer considered a test,
so move it out of the 'test' namespace.

Signed-off-by: Yann E. MORIN <[email protected]>
@ymorin-orange ymorin-orange added enhancement New feature or request Python Python code labels Oct 21, 2024
@ymorin-orange ymorin-orange added this to the Sprint 3 milestone Oct 21, 2024
@ymorin-orange ymorin-orange self-assigned this Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Python Python code
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant