Skip to content

Commit 4ccc57f

Browse files
authored
Merge pull request #44 from elastic/main
Merge main into 8.16 branch
2 parents 61353d1 + 5ddf57c commit 4ccc57f

File tree

5 files changed

+228
-21
lines changed

5 files changed

+228
-21
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ These pages detail the components and how to configure the EDOT Collector.
2323
- [Manual configurations](docs/manual-configuration.md): Manually configure the EDOT Collector to send data to Elastic Observability.
2424
- [Limitations](docs/collector-limitations.md): Understand the current limitations of the EDOT Collector.
2525

26-
## Kubernetes Observability using the EDOT Collector
26+
## Unified Kubernetes Observability with Elastic Distributions of OpenTelemetry
2727

28-
- [Kubernetes guided onboarding](docs/kubernetes/operator/README.md): Use the guided onboarding to send Kubernetes logs, metrics, and application traces to Elasticsearch using the EDOT Collector and [OpenTelemetry Operator](https://github.com/open-telemetry/opentelemetry-operator/).
28+
- [Kubernetes guided onboarding](docs/kubernetes/operator/README.md): Use the guided onboarding to send Kubernetes logs, metrics, and application traces to Elasticsearch using the [OpenTelemetry Operator](https://github.com/open-telemetry/opentelemetry-operator/) to orchestrate the EDOT Collectors and EDOT SDK instances you will need.
29+
- [Instrumenting applications](docs/kubernetes/operator/instrumenting-applications.md) on Kubernetes: Collect application data using EDOT language SDKs.
2930

30-
## Collect application data using the EDOT language SDKs
31+
## Collect application data using EDOT language SDKs
3132

3233
Elastic offers several Distributions that extend [OpenTelemetry language SDKs](https://opentelemetry.io/docs/languages/). The following languages are currently available:
3334

docs/kubernetes/operator/README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This guide describes how to:
2121

2222
- Elastic Stack (self-managed or [Elastic Cloud](https://www.elastic.co/cloud)) version 8.16.0 or higher, or an [Elasticsearch serverless](https://www.elastic.co/docs/current/serverless/elasticsearch/get-started) project.
2323

24-
- A Kubernetes version supported by the OpenTelemetry Operator (refer to the operator's [compatibility matrix](https://github.com/open-telemetry/opentelemetry-operator?#compatibility-matrix) for more details).
24+
- A Kubernetes version supported by the OpenTelemetry Operator (refer to the operator's [compatibility matrix](https://github.com/open-telemetry/opentelemetry-operator/blob/main/docs/compatibility.md#compatibility-matrix) for more details).
2525

2626
## Compatibility Matrix
2727

@@ -169,9 +169,11 @@ metadata:
169169
instrumentation.opentelemetry.io/inject-<LANGUAGE>: "opentelemetry-operator-system/elastic-instrumentation"
170170
```
171171
172-
where <LANGUAGE> is one of: `go` , `java`, `nodejs`, `python`, `dotnet`
172+
where ``<LANGUAGE>`` is one of: `go` , `java`, `nodejs`, `python`, `dotnet`
173173

174-
For detailed instructions and examples on how to instrument applications in Kubernetes using the OpenTelemetry Operator, refer to this guide (TBD-add link and document).
174+
For detailed instructions and examples on how to instrument applications in Kubernetes using the OpenTelemetry Operator, refer to [Instrumenting applications](/docs/kubernetes/operator/instrumenting-applications.md).
175+
176+
For troubleshooing details and verification steps, refer to [Troubleshooting auto-instrumentation](/docs/kubernetes/operator/troubleshoot-auto-instrumentation.md).
175177

176178
## Limitations
177179

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Instrumenting applications with EDOT SDKs on Kubernetes
2+
3+
Elastic Distributions of OpenTelemetry (EDOT) SDKs cover multiple languages:
4+
5+
* [EDOT Java](https://github.com/elastic/elastic-otel-java)
6+
* [EDOT .NET](https://github.com/elastic/elastic-otel-dotnet)
7+
* [EDOT Node.js](https://github.com/elastic/elastic-otel-node)
8+
* [EDOT Python](https://github.com/elastic/elastic-otel-python)
9+
* [EDOT PHP](https://github.com/elastic/elastic-otel-php/)
10+
11+
This section provides guidance and examples for applications instrumentation in a Kubernetes environment for all supported languages.
12+
13+
In Kubernetes environments with the OpenTelemetry Operator, [**automatic (or zero-code) instrumentation**](https://opentelemetry.io/docs/kubernetes/operator/automatic/) simplifies the process by injecting and configuring instrumentation libraries into the targeted Pods.
14+
15+
On the other hand, **manual instrumentation** with OpenTelemetry involves adding specific OpenTelemetry SDKs and APIs directly into your application’s code. This approach provides more granular control over what and how data is captured, allowing you to customize trace spans, metrics, and logging based on your application’s logic.
16+
17+
## Table of contents
18+
19+
- [Supported languages](#supported-languages)
20+
- [Prerequisites](#prerequisites)
21+
- [Auto-instrumentation basics](#auto-instrumentation-basics)
22+
- [Configuring auto-instrumentation](#configuring-auto-instrumentation)
23+
- [Advanced configuration](#advanced-configuration)
24+
- [Manual instrumentation](#manual-instrumentation)
25+
26+
## Supported languages
27+
28+
The following table illustrates the different languages supported by OpenTelemetry (OTel) and the Elastic Stack, the type of SDK/API used for instrumentation (either zero-code or source code dependencies), and the corresponding deployment types (on-premises, ESS, or serverless) for each language.
29+
30+
| Language | OTel SDK/API Type | Deployment Model Support |
31+
|------------|---------------------------------------------------------|-------------------------------------|
32+
| Java | EDOT Java - **zero-code instrumentation** | All deployment types |
33+
| Node.js | EDOT Node.js - **zero-code instrumentation** | All deployment types |
34+
| .NET | EDOT .NET - **zero-code instrumentation** | All deployment types |
35+
| PHP | EDOT PHP - source code dependencies | All deployment types |
36+
| Python | EDOT Python - **zero-code instrumentation** | All deployment types |
37+
| Swift | EDOT Swift - source code dependencies | ESS, on-premises |
38+
| Android | EDOT Android - source code dependencies | ESS, on-premises |
39+
| Javascript | Vanilla OTel RUM SDK/API - source code dependencies | ESS, on-premises |
40+
| Rust | Vanilla OTel Rust SDK/API - source code dependencies | All deployment types |
41+
| Ruby | Vanilla OTel Ruby SDK/API - source code dependencies | All deployment types |
42+
| Go | Vanilla OTel Go SDK/API - **zero-code instrumentation** | All deployment types |
43+
| C++ | Vanilla OTel C++ SDK/API - source code dependencies | All deployment types |
44+
45+
## Prerequisites
46+
47+
Before starting with application auto-instrumentation, ensure the following prerequisites are in place for proper setup:
48+
 
49+
- Install the OpenTelemetry operator and EDOT collectors following the [getting started guide](./README.md).
50+
- Ensure a valid `kind: Instrumentation` object exists in the cluster.
51+
52+
## Auto-instrumentation basics
53+
54+
Zero-code instrumentation is handled by the operator through `Instrumentation` objects, used to automatically inject the necessary SDKs and configuration into application workloads.
55+
56+
If you followed the [getting started guide](./README.md) to install the operator, there should be an `Instrumentation` object with name `elastic-instrumentation` in namespace `opentelemetry-operator-system`:
57+
58+
```bash
59+
kubectl get instrumentation -A
60+
NAMESPACE NAME AGE ENDPOINT SAMPLER SAMPLER ARG
61+
opentelemetry-operator-system elastic-instrumentation 5d20h http://opentelemetry-kube-stack-daemon-collector.opentelemetry-operator-system.svc.cluster.local:4318 parentbased_traceidratio 1.0
62+
```
63+
64+
The `Instrumentation` object stores important parameters:
65+
66+
- The **exporter endpoint** represents the destination for the traces, in this case the HTTP receiver configured in the EDOT DaemonSet Collector. That endpoint has to be reachable by the Pods being instrumented.
67+
68+
```yaml
69+
exporter:
70+
endpoint: http://opentelemetry-kube-stack-daemon-collector.opentelemetry-operator-system.svc.cluster.local:4318
71+
```
72+
73+
- Language-specific **images** used by the operator to inject the appropriate library into each Pod.
74+
75+
```yaml
76+
dotnet:
77+
image: docker.elastic.co/observability/elastic-otel-dotnet:edge
78+
java:
79+
image: docker.elastic.co/observability/elastic-otel-javaagent:1.0.0
80+
nodejs:
81+
image: docker.elastic.co/observability/elastic-otel-node:0.4.1
82+
python:
83+
image: docker.elastic.co/observability/elastic-otel-python:0.3.0
84+
```
85+
86+
## Configuring auto-instrumentation
87+
88+
To enable auto-instrumentation, add the corresponding language annotation to the **Pods** template (`spec.template.metadata.annotations`) in your Deployment or relevant workload object (StatefulSet, Job, CronJob, etc.).
89+
90+
```yaml
91+
apiVersion: apps/v1
92+
kind: Deployment
93+
metadata:
94+
name: myapp
95+
spec:
96+
...
97+
template:
98+
metadata:
99+
annotations:
100+
instrumentation.opentelemetry.io/inject-<LANGUAGE>: "opentelemetry-operator-system/elastic-instrumentation"
101+
...
102+
spec:
103+
containers:
104+
- image: myapplication-image
105+
name: app
106+
...
107+
```
108+
109+
where ``<LANGUAGE>`` is one of: `go` , `java`, `nodejs`, `python`, `dotnet`
110+
111+
> [!NOTE]
112+
> Ensure you add the annotations at Pod level and not directly at the workload `spec` level (Deployment, Job, etc.).
113+
> Ensure the annotation value must points to an existing `Instrumentation` object.
114+
115+
Alternatively, you can enable auto-instrumentation by adding the annotation at the **namespace level**. This approach automatically applies instrumentation to all Pods within the specified namespace.
116+
117+
```yaml
118+
apiVersion: v1
119+
kind: Namespace
120+
metadata:
121+
name: mynamespace
122+
annotations:
123+
instrumentation.opentelemetry.io/inject-<LANGUAGE>: "opentelemetry-operator-system/elastic-instrumentation"
124+
```
125+
126+
After adding annotations to Pods or Namespaces, the applications must be restarted for the instrumentation injection to take effect:
127+
128+
```bash
129+
kubectl rollout restart deployment/my-deployment
130+
```
131+
132+
In case you have multiple Instrumentation objects with different settings or images, ensure you point your Pods to the the desired `Instrumentation` objects in the annotations.
133+
134+
The possible values for the annotation are detailed in the [Operator documentation](https://opentelemetry.io/docs/kubernetes/operator/automatic/#add-annotations-to-existing-deployments). For reference purposes, the values are:
135+
136+
- `"true"`: to inject Instrumentation resource with default name from the current namespace.
137+
- `"my-instrumentation"`: to inject Instrumentation instance with name `"my-instrumentation"` in the current namespace.
138+
- `"my-other-namespace/my-instrumentation"`: to inject Instrumentation instance with name `"my-instrumentation"` from another namespace `"my-other-namespace"`.
139+
- `"false"`: do not inject.
140+
141+
### Namespace based annotations example
142+
143+
The following example creates a namespace with an annotation to instrument all Pods of the namespace with `java` libraries.
144+
145+
```
146+
kubectl create namespace java-apps
147+
148+
#Annotate app namespace
149+
kubectl annotate namespace java-apps instrumentation.opentelemetry.io/inject-java="opentelemetry-operator-system/elastic-instrumentation"
150+
151+
# Run a java example application in the namespace
152+
kubectl run otel-test -n java-apps --env OTEL_INSTRUMENTATION_METHODS_INCLUDE="test.Testing[methodB]" --image docker.elastic.co/demos/apm/k8s-webhook-test
153+
```
154+
155+
## Advanced configuration
156+
157+
You can apply OTEL specific configuration to your applications at two different levels:
158+
- At Pod/container level, by using OTEL related environment variables.
159+
- At `Instrumentation` object level, for example configuring different settings per language.
160+
161+
Use cases:
162+
- Change the library to be injected.
163+
- Change the exporter endpoint.
164+
- Apply certain logging level settings (OTEL_LOG_LEVEL).
165+
166+
### Adding extra Instrumentation objects
167+
168+
Consider also the creation of different `Instrumentation` objects for different purposes, such as:
169+
170+
- Different configuration options for certain languages.
171+
- Trying out different versions of the SDKs.
172+
173+
(TBD: add instructions and references about Instrumentation objects)
174+
175+
176+
## Manual instrumentation
177+
(TBD, in-progress)
178+
179+
The manual instrumentation...
180+
Configuration requirements (does every language has its own requirements)?
181+
Exporter destination? HTTP vs OTLP? does each EDOT SDK support different protocols?
182+

resources/kubernetes/operator/helm/values.yaml

+37-15
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ defaultCRConfig:
2323
targetAllocator:
2424
enabled: false # Enable/disable the Operator's Target allocator.
2525
# Refer to: https://github.com/open-telemetry/opentelemetry-operator/tree/main/cmd/otel-allocator
26-
env:
27-
- name: ELASTIC_AGENT_OTEL
28-
value: '"true"'
29-
- name: ELASTIC_ENDPOINT
30-
valueFrom:
31-
secretKeyRef:
32-
name: elastic-secret-otel
33-
key: elastic_endpoint
34-
- name: ELASTIC_API_KEY
35-
valueFrom:
36-
secretKeyRef:
37-
name: elastic-secret-otel
38-
key: elastic_api_key
3926

4027
clusterRole:
4128
rules:
@@ -59,6 +46,19 @@ collectors:
5946
# requests:
6047
# cpu: 100m
6148
# memory: 500Mi
49+
env:
50+
- name: ELASTIC_AGENT_OTEL
51+
value: '"true"'
52+
- name: ELASTIC_ENDPOINT
53+
valueFrom:
54+
secretKeyRef:
55+
name: elastic-secret-otel
56+
key: elastic_endpoint
57+
- name: ELASTIC_API_KEY
58+
valueFrom:
59+
secretKeyRef:
60+
name: elastic-secret-otel
61+
key: elastic_api_key
6262
config:
6363
exporters:
6464
# [Debug exporter](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/debugexporter/README.md)
@@ -219,11 +219,33 @@ collectors:
219219
# Configure the pods resources to control CPU and memory usage.
220220
resources:
221221
limits:
222-
cpu: 100m
223-
memory: 500Mi
222+
cpu: 1500m
223+
memory: 1500Mi
224224
requests:
225225
cpu: 100m
226226
memory: 500Mi
227+
env:
228+
# Work around for open /mounts error: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35990
229+
- name: HOST_PROC_MOUNTINFO
230+
value: ""
231+
- name: ELASTIC_AGENT_OTEL
232+
value: '"true"'
233+
- name: ELASTIC_ENDPOINT
234+
valueFrom:
235+
secretKeyRef:
236+
name: elastic-secret-otel
237+
key: elastic_endpoint
238+
- name: ELASTIC_API_KEY
239+
valueFrom:
240+
secretKeyRef:
241+
name: elastic-secret-otel
242+
key: elastic_api_key
243+
- name: GOMAXPROCS
244+
valueFrom:
245+
resourceFieldRef:
246+
resource: limits.cpu
247+
- name: GOMEMLIMIT
248+
value: "1025MiB"
227249
presets:
228250
logsCollection:
229251
enabled: true # Enable/disable the collection of node's logs.

0 commit comments

Comments
 (0)