Skip to content

Commit

Permalink
Update python getting started guid
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwest committed Jun 3, 2024
1 parent c003eb9 commit 0cd3d65
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 374 deletions.
11 changes: 11 additions & 0 deletions getting-started-guides/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ services:
- OTEL_RESOURCE_ATTRIBUTES=service.instance.id=123
ports:
- 8080
python:
build: python
environment:
- OTEL_SERVICE_NAME=getting-started-python
- OTEL_EXPORTER_OTLP_ENDPOINT
- OTEL_EXPORTER_OTLP_HEADERS
- OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT=4095
- OTEL_RESOURCE_ATTRIBUTES=service.instance.id=123
ports:
- 8080
ruby:
build: ruby
environment:
Expand All @@ -54,4 +64,5 @@ services:
- dotnet
- go
- javascript
- python
- ruby
46 changes: 46 additions & 0 deletions getting-started-guides/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# syntax=docker/dockerfile:1

ARG PYTHON_VERSION=3.12.2
FROM python:${PYTHON_VERSION}-slim as base

# Prevents Python from writing pyc files.
# ENV PYTHONDONTWRITEBYTECODE=1

# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
# ENV PYTHONUNBUFFERED=1

WORKDIR /app

# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
# Leverage a bind mount to requirements.txt to avoid having to copy them into
# into this layer.
RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.txt,target=requirements.txt \
python -m pip install -r requirements.txt

ENV OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true

RUN opentelemetry-bootstrap -a install

COPY . .

# Switch to the non-privileged user to run the application.
USER appuser

EXPOSE 8080

CMD opentelemetry-instrument --logs_exporter otlp python3 app.py
46 changes: 0 additions & 46 deletions getting-started-guides/python/Instrumented/README.md

This file was deleted.

91 changes: 0 additions & 91 deletions getting-started-guides/python/Instrumented/app.py

This file was deleted.

14 changes: 0 additions & 14 deletions getting-started-guides/python/Instrumented/call-app.ps1

This file was deleted.

21 changes: 0 additions & 21 deletions getting-started-guides/python/Instrumented/call-app.sh

This file was deleted.

7 changes: 0 additions & 7 deletions getting-started-guides/python/Instrumented/load-generator.ps1

This file was deleted.

10 changes: 0 additions & 10 deletions getting-started-guides/python/Instrumented/load-generator.sh

This file was deleted.

31 changes: 0 additions & 31 deletions getting-started-guides/python/Instrumented/requirements.txt

This file was deleted.

45 changes: 45 additions & 0 deletions getting-started-guides/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Getting Started Guide - Python

This is a simple application instrumented with [OpenTelemetry Python](https://github.com/open-telemetry/opentelemetry-python).
It demonstrates how to configure OpenTelemetry Python to send data to New Relic.

## Requirements

* [Python](https://www.python.org/downloads/)
* [A New Relic account](https://one.newrelic.com/)
* [A New Relic license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#license-key)

## Running the application

1. Set the following environment variables to configure OpenTelemetry to send
data to New Relic:

```shell
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.nr-data.net
export OTEL_EXPORTER_OTLP_HEADERS=api-key=<your_license_key>
export OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT=4095
export OTEL_SERVICE_NAME=getting-started-python
export OTEL_RESOURCE_ATTRIBUTES=service.instance.id=123
```

* If your account is based in the EU, set the endpoint to: [https://otlp.eu01.nr-data.net](https://otlp.eu01.nr-data.net)

2. Run the following command to install dependencies:

```shell
python -m pip install -r requirements.txt
opentelemetry-bootstrap -a install
```

3. Run the application with the following command and open
[http://localhost:8080/fibonacci?n=1](http://localhost:8080/fibonacci?n=1)
in your web browser to ensure it is working.

```shell
opentelemetry-instrument --logs_exporter otlp python3 app.py
```

4. Experiment with providing different values for `n` in the query string.
Valid values are between 1 and 90. Values outside this range cause an error
which will show up in New Relic.
21 changes: 0 additions & 21 deletions getting-started-guides/python/Uninstrumented/app.py

This file was deleted.

14 changes: 0 additions & 14 deletions getting-started-guides/python/Uninstrumented/call-app.ps1

This file was deleted.

Loading

0 comments on commit 0cd3d65

Please sign in to comment.