Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
# elastic-opentelemetry -- Elastic Distribution of OpenTelemetry Python
# Elastic Distribution of OpenTelemetry Python

`elastic-opentelemetry` is the Elastic Distribution of OpenTelemetry Python.
> [!WARNING]
> The Elastic Distribution of OpenTelemetry Python is not yet recommended for production use. Functionality may be changed or removed in future releases. Alpha releases are not subject to the support SLA of official GA features.
>
> We welcome your feedback! You can reach us by [opening a GitHub issue](https://github.com/elastic/elastic-otel-python/issues) or starting a discussion thread on the [Elastic Discuss forum](https://discuss.elastic.co/tags/c/observability/apm/58/python).
## Installation
<!--
Is the Python distro built on top of the OTel Python agent (https://opentelemetry.io/docs/zero-code/python/)?
Or the OTel Python SDK (https://opentelemetry.io/docs/languages/python/)?
Or neither?
-->
The Elastic Distribution of OpenTelemetry Python (EDOT Python) is a customized version of the [OpenTelemetry SDK for Python](https://opentelemetry.io/docs/languages/python).
<!-- Is this true of the Python distro? -->
EDOT Python makes it easier to get started using OpenTelemetry in your Python applications through strictly OpenTelemetry native means, while also providing a smooth and rich out of the box experience with [Elastic Observability](https://www.elastic.co/observability). It's an explicit goal of this distribution to introduce **no new concepts** in addition to those defined by the wider OpenTelemetry community.

With EDOT Python you have access to all the features of the OpenTelemetry Python agent plus:

<!--
These are some examples from other distro docs.
Feel free to delete or edit these items or add new items to this list.
-->
* Access to SDK improvements and bug fixes contributed by the Elastic team _before_ the changes are available upstream in OpenTelemetry repositories.
* Access to optional features that can enhance OpenTelemetry data that is being sent to Elastic.
* Elastic-specific processors that ensure optimal compatibility when exporting OpenTelemetry signal data to an Elastic backend like an Elastic Observability deployment.
* Preconfigured collection of tracing and metrics signals, applying some opinionated defaults, such as which sources are collected by default.
* Ensuring that the OpenTelemetry protocol (OTLP) exporter is enabled by default.

**Ready to try out EDOT Python?** Follow the step-by-step instructions in [Get started](./docs/get-started.md).

## Read the docs

* [Get started](./docs/get-started.md)
* [Configuration](./docs/configure.md)

## Install

```bash
pip install elastic-opentelemetry
```

<!-- I'll let you decide how much to keep here from the content below vs rely on content in the docs directory -->

## Usage

Our distribution does not install any instrumentation package by default, instead it relies on the
Expand Down
67 changes: 67 additions & 0 deletions docs/configure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!--
Goal of this doc:
Provide a complete reference of all available configuration options and where/how they can be set.
Any Elastic-specific configuration options are listed directly.
General OpenTelemetry configuration options are linked.
-->

# Configuration

Configure the Elastic Distribution of OpenTelemetry Python (EDOT Python) to send data to Elastic.

<!-- How users set configuration options -->
## Configuration method

<!-- Is this the right link to OpenTelemetry docs? -->
Configuration of the OpenTelemetry SDK should be performed through the mechanisms [documented on the OpenTelemetry website](https://opentelemetry.io/docs/zero-code/python/configuration/). EDOT Python is typically configured with `OTEL_*` environment variables defined by the OpenTelemetry spec. For example:

<!-- Would this example work? -->
```sh
export OTEL_RESOURCE_ATTRIBUTES=service.name=<app-name>
export OTEL_EXPORTER_OTLP_ENDPOINT=https://my-deployment.apm.us-west1.gcp.cloud.es.io
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer P....l"
opentelemetry-instrument <command to start your service>
```

<!-- List all available configuration options -->
## Configuration options

<!-- Is the distro an extension of the OTel Python SDK? The agent? Or neither? -->
Because the Elastic Distribution of OpenTelemetry Python is an extension of the OpenTelemetry Python SDK, it supports:

* [OpenTelemetry configuration options](#opentelemetry-configuration-options)
* [Configuration options that are _only_ available in EDOT Python](#configuration-options-that-are-only-available-in-edot-python)

### OpenTelemetry configuration options

EDOT Python supports all configuration options listed in the [OpenTelemetry General SDK Configuration documentation](https://opentelemetry.io/docs/languages/sdk-configuration/general/) and [OpenTelemetry Python SDK](https://opentelemetry.io/docs/languages/python).

<!-- Is this true? Or did you list these in the README for some other reason? -->
EDOT Python uses different defaults than the OpenTelemetry Python SDK for the following configuration options:

| Option | EDOT Python default | OpenTelemetry Python agent default |
|---|---|---|
| `OTEL_TRACES_EXPORTER` | `otlp` | ?? ([docs](#)) |
| `OTEL_METRICS_EXPORTER` | `otlp` | ?? ([docs](#)) |
| `OTEL_EXPORTER_OTLP_PROTOCOL` | `grpc` | ?? ([docs](#)) |
| `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` | `process_runtime,otel,telemetry_distro` | ?? ([docs](#)) |


### Configuration options that are _only_ available in EDOT Python

In addition to general OpenTelemetry configuration options, there are two kinds of configuration options that are _only_ available in EDOT Python.

<!-- This is true for the Java distro, is it also true of the Python distro? -->
**Elastic-authored options that are not yet available upstream**

Additional `OTEL_` options that Elastic plans to contribute upstream to the OpenTelemetry Python SDK, but are not yet available in the OpenTelemetry Python SDK.

_Currently there are no additional `OTEL_` options waiting to be contributed upstream._

**Elastic-specific options**

`ELASTIC_OTEL_` options that are specific to Elastic and will always live in EDOT Python (in other words, they will _not_ be added upstream):

| Option(s) | Default | Description |
|---|---|---|
| `ELASTIC_OTEL_SYSTEM_METRICS_ENABLED` | `false` | When sets to `true`, sends *system namespace* metrics. |
125 changes: 125 additions & 0 deletions docs/get-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!--
Goal of this doc:
The user is able to successfully see data from their Python application
make it to the Elastic UI via EDOT Python
-->

# Get started

This guide shows you how to use the Elastic Distribution of OpenTelemetry Python (EDOT Python) to instrument your Python application and send OpenTelemetry data to an Elastic Observability deployment.

**Already familiar with OpenTelemetry?** It's an explicit goal of this distribution to introduce _no new concepts_ outside those defined by the wider OpenTelemetry community.

**New to OpenTelemetry?** This section will guide you through the _minimal_ configuration options to get EDOT Python set up in your application. You do _not_ need any existing experience with OpenTelemetry to set up EDOT Python initially. If you need more control over your configuration after getting set up, you can learn more in the [OpenTelemetry documentation](https://opentelemetry.io/docs/zero-code/python/agent/).

<!-- What the user needs to know and/or do before they install EDOT Python -->
<!-- Is this missing anything? -->
## Prerequisites

Before getting started, you'll need somewhere to send the gathered OpenTelemetry data, so it can be viewed and analyzed. EDOT Python supports sending data to any OpenTelemetry protocol (OTLP) endpoint, but this guide assumes you are sending data to an [Elastic Observability](https://www.elastic.co/observability) cloud deployment. You can use an existing one or set up a new one.

<details>
<summary><strong>Expand for setup instructions</strong></summary>

To create your first Elastic Observability deployment:

1. Sign up for a [free Elastic Cloud trial](https://cloud.elastic.co/registration) or sign into an existing account.
1. Go to <https://cloud.elastic.co/home>.
1. Click **Create deployment**.
1. When the deployment is ready, click **Open** to visit your Kibana home page (for example, `https://{DEPLOYMENT_NAME}.kb.{REGION}.cloud.es.io/app/home#/getting_started`).
</details>

<!-- ✅ How to install EDOT Python -->
## Install

### Install the distribution

Install EDOT Python:

```bash
pip install elastic-opentelemetry
```

### Install the available instrumentation

EDOT Python does not install any instrumentation package by default, instead it relies on the
`opentelemetry-bootstrap` command to scan the installed packages and install the available instrumentation.
The following command will install all the instrumentations available for libraries found installed
in your environment:

```bash
opentelemetry-bootstrap --action=install
```

> [!NOTE]
> Add this command every time you deploy an updated version of your application (in other words, add it to your container image build process).
<!-- ✅ Start-to-finish operation -->
## Send data to Elastic

After installing EDOT Python, configure and initialize it to start sending data to Elastic.

<!-- ✅ Provide _minimal_ configuration/setup -->
### Configure EDOT Python

To configure EDOT Python, at a minimum you'll need your Elastic Observability cloud deployment's OTLP endpoint and
authorization data to set a few `OTLP_*` environment variables that will be available when running EDOT Python:

* `OTEL_RESOURCE_ATTRIBUTES`: Use this to add a service name that will make it easier to recognize your application when reviewing data sent to Elastic.
* `OTEL_EXPORTER_OTLP_ENDPOINT`: The full URL of the endpoint where data will be sent.
* `OTEL_EXPORTER_OTLP_HEADERS`: A comma-separated list of `key=value` pairs that will
be added to the headers of every request. This is typically used for authentication information.

<!--
These are the instructions used in other distro docs, but in the README in this repo
it looks like you might be recommending using an API key rather than using the secret
token method used in the setup guides in Kibana.
-->
You can find the values of the endpoint and header variables in Kibana's APM tutorial. In Kibana:

1. Go to **Setup guides**.
1. Select **Observability**.
1. Select **Monitor my application performance**.
1. Scroll down and select the **OpenTelemetry** option.
1. The appropriate values for `OTEL_EXPORTER_OTLP_ENDPOINT` and `OTEL_EXPORTER_OTLP_HEADERS` are shown there.

Here's an example:

```sh
export OTEL_RESOURCE_ATTRIBUTES=service.name=<app-name>
export OTEL_EXPORTER_OTLP_ENDPOINT=https://my-deployment.apm.us-west1.gcp.cloud.es.io
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer P....l"
```

### Run EDOT Python

Then wrap your service invocation with `opentelemetry-instrument`, which is the wrapper that provides _automatic instrumentation_:

```bash
opentelemetry-instrument <command to start your service>
```

For example, a web service running with gunicorn may look like this:

```bash
opentelemetry-instrument gunicorn main:app
```

<!-- ✅ What success looks like -->
## Confirm that EDOT Python is working

To confirm that EDOT Python has successfully connected to Elastic:

1. Go to **APM****Traces**.
1. You should see the name of the service to which you just added EDOT Python. It can take several minutes after initializing EDOT Python for the service to show up in this list.
1. Click on the name in the list to see trace data.

<!-- Is this true for the Python distro? -->
> [!NOTE]
> There may be no trace data to visualize unless you have _used_ your application since initializing EDOT Python.
<!-- ✅ What they should do next -->
## Next steps

* Reference all available [configuration options](./configure.md).
* Learn more about viewing and interpreting data in the [Observability guide](https://www.elastic.co/guide/en/observability/current/apm.html).