Skip to content

Add python telemetry hopper to land telemetry data in Azure Monitor #249

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aditjha-msft
Copy link
Contributor

@aditjha-msft aditjha-msft commented May 27, 2025

This PR introduces the Python telemetry hopper which will be used in the container scenario to forward telemetry from image customizer to Azure Monitor. This approach is needed for a variety of reasons, most importantly because Azure Monitor doesn't provide a Go SDK for instrumentation, and other solutions come with security and auth challenges. See design doc here: Image Customizer OTel Integration.docx
This will work alongside PR: #241

if --disable-telemetry is passed in to the docker command, the telemetry hopper will not be started and collection and export will be disabled:

 docker run \
   --rm \
   --privileged=true \
   -v /dev:/dev \
   -v "$HOME/staging:/mnt/staging:z" \
   mcr.microsoft.com/azurelinux/imagecustomizer:0.13.0 \
   imagecustomizer \
     --disable-telemetry
     --image-file "/mnt/staging/image.vhdx" \
     --config-file "/mnt/staging/image-config.yaml" \
     --build-dir "/build" \
     --output-image-format "vhdx" \
     --output-image-file "/mnt/staging/out/image.vhdx"

Checklist

  • Tests added/updated
  • Documentation updated (if needed)
  • Code conforms to style guidelines

@aditjha-msft aditjha-msft force-pushed the user/aditjha/pythonAzureMonitor branch 2 times, most recently from ee91462 to f866cfc Compare May 29, 2025 08:39
@aditjha-msft aditjha-msft marked this pull request as ready for review May 29, 2025 18:49
@aditjha-msft aditjha-msft requested a review from a team as a code owner May 29, 2025 18:49
aditjha-msft added a commit that referenced this pull request May 30, 2025
This PR introduces support for using the OTEL Go sdk to instrument the
tool using OTEL standards and practices. It provides initialization
logic needed for a global tracer to be used across the tool's execution.
For starters, the PR adds a customization time span, with more telemetry
to be added in follow up PRs that help with data collection tied to the
tool's KPIs.

The PR also adds logic to disable telemetry, and uses a no-op tracer
when `--disable-telemetry` is passed in. This follows OTEL standardized
method of disabling telemetry collection in a clean manner.

As part of telemetry initialization, the `telemetry.go` file has been
added to set up the OTEL tracer and the OTLP grpc exporter. The exporter
will send data to a Python service listening at the local port, which
will then forward the data to Azure Monitor.

In the effort of splitting up PRs in chunks, the PR for the complement
Python telemetry service is here:
#249.

---

### **Checklist**
- [x] Tests added/updated
- [x] Documentation updated (if needed)
- [x] Code conforms to style guidelines
@aditjha-msft aditjha-msft force-pushed the user/aditjha/pythonAzureMonitor branch from 7b45fd3 to 2a3dc66 Compare May 31, 2025 00:12
@aditjha-msft aditjha-msft requested a review from a team May 31, 2025 00:15
@@ -0,0 +1,101 @@
asgiref==3.8.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there so many packages in this file?

gonum.org/v1/gonum v0.15.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there changes to the go.mod file?

@@ -6,7 +6,18 @@ ARG BASE_IMAGE="mcr.microsoft.com/azurelinux/base/core:3.0"
FROM ${BASE_IMAGE}
RUN tdnf update -y && \
tdnf install -y qemu-img rpm coreutils util-linux systemd openssl \
sed createrepo_c squashfs-tools cdrkit parted e2fsprogs dosfstools \
xfsprogs zstd veritysetup grub2 grub2-pc systemd-ukify binutils lsof
sed createrepo_c squashfs-tools cdrkit parted e2fsprogs dosfstools \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore indent.

RUN python3 -m venv /opt/telemetry-venv && \
/opt/telemetry-venv/bin/pip install --no-cache-dir -r /usr/local/bin/requirements.txt

RUN chmod +x /usr/local/bin/entrypoint.sh && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this for the other script files added to the container.

Note: Git will save/restore the execute bit (but not any other permission).


# Start telemetry service if enabled
if [[ "$ENABLE_TELEMETRY" == "true" ]]; then
/opt/telemetry-venv/bin/python /usr/local/bin/telemetry_hopper.py > /dev/null 2>&1 || true &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What stops this process?

from opentelemetry.proto.trace.v1.trace_pb2 import Span as ProtoSpan
from opentelemetry.proto.common.v1.common_pb2 import KeyValue

DEFAULT_GRPC_PORT = 4317
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to pass the port number in as a param so that there is only 1 source of truth for what this value is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants