-
Notifications
You must be signed in to change notification settings - Fork 34
K8s auto-instrumentation details and example (Node.js) #59
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
03f6d51
instrumenting-nodejs.md draft added
eedugon 930a908
commented section made visible
eedugon 933a774
getting started guide link updated
eedugon df8b32c
example removed
eedugon d2a8261
example removed
eedugon 90f4db5
example removed
eedugon 49f8239
example removed
eedugon c9da9b0
Merge branch 'main' into k8s_instrumenting_nodejs
eedugon 4a15e4d
content aligned with other guides, indentation fixed, and Trent's sug…
eedugon 890b8cb
pods made plural
eedugon 366ee27
traffic generation tip added
eedugon b2be789
Update docs/kubernetes/operator/instrumenting-nodejs.md
eedugon dce176c
kubectl port-forward link added
eedugon 4afebb4
Update docs/kubernetes/operator/instrumenting-nodejs.md
eedugon 9c94031
Update docs/kubernetes/operator/instrumenting-nodejs.md
eedugon ccb8af5
Update docs/kubernetes/operator/instrumenting-nodejs.md
eedugon 78a54d5
Update docs/kubernetes/operator/instrumenting-nodejs.md
eedugon 5e0cfe1
indentation and minor fixes
eedugon 543dd99
link to nodejs doc added in instrumenting_applications.md
eedugon 2839fcc
link to nodejs doc added in instrumenting_applications.md
eedugon e5bbaae
removed port-forward hint because the user should know how to generat…
eedugon 94b095e
Update docs/kubernetes/operator/instrumenting-nodejs.md
eedugon fbb486d
env var check sentence moved upwards
eedugon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| # Instrumenting Node.js applications with EDOT SDKs on Kubernetes | ||
|
|
||
| This document focuses on instrumenting Node.js applications on Kubernetes, using the OpenTelemetry Operator, the Elastic Distribution of OpenTelemetry (EDOT) Collectors, and the [EDOT Node.js](https://github.com/elastic/elastic-otel-nodejs) SDK. | ||
|
|
||
| - For general knowledge about the EDOT Node.js SDK, refer to the [getting started guide](https://github.com/elastic/elastic-otel-node/blob/main/packages/opentelemetry-node/docs/get-started.md) and [configuration](https://github.com/elastic/elastic-otel-node/blob/main/packages/opentelemetry-node/docs/configure.md). | ||
| - For Node.js auto-instrumentation specifics, refer to [OpenTelemetry Operator Node.js auto-instrumentation](https://opentelemetry.io/docs/kubernetes/operator/automatic/#nodejs). | ||
trentm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - For general information about instrumenting applications on kubernetes, refer to [instrumenting applications](./instrumenting-applications.md). | ||
|
|
||
| ## Instrument a Node.js app with EDOT Node.js SDK on Kubernetes | ||
|
|
||
| <!-- | ||
| Useful links: | ||
| - Example: https://github.com/elastic/elastic-otel-node/tree/main/examples/otel-operator/ documented at https://github.com/elastic/elastic-otel-node/blob/main/DEVELOPMENT.md#testing-k8s-auto-instrumentation-with-otel-operator | ||
| (not user friendly, but we could use it in the future if we want to add a proper example here) | ||
| --> | ||
|
|
||
| In this example, you'll learn how to: | ||
|
|
||
| - Enable auto-instrumentation of a Node.js application using one of the following supported methods: | ||
| - Adding an annotation to the deployment Pods. | ||
| - Adding an annotation to the namespace. | ||
| - Verify that auto-instrumentation libraries are injected and configured correctly. | ||
| - Confirm data is flowing to **Kibana Observability**. | ||
|
|
||
| For this example, we assume the application you're instrumenting is a deployment named `nodejs-app` running in the `nodejs-ns` namespace. | ||
|
|
||
| 1. Ensure you have successfully [installed the OpenTelemetry Operator](./README.md), and confirm that the following `Instrumentation` object exists in the system: | ||
|
|
||
| ```bash | ||
| $ kubectl get instrumentation -n opentelemetry-operator-system | ||
| NAME AGE ENDPOINT | ||
| elastic-instrumentation 107s http://opentelemetry-kube-stack-daemon-collector.opentelemetry-operator-system.svc.cluster.local:4318 | ||
| ``` | ||
| > [!NOTE] | ||
| > If your `Instrumentation` object has a different name or is created in a different namespace, you will have to adapt the annotation value in the next step. | ||
|
|
||
| 2. Enable auto-instrumentation of your Node.js application using one of the following methods: | ||
|
|
||
| - Edit your application workload definition and include the annotation under `spec.template.metadata.annotations`: | ||
|
|
||
| ```yaml | ||
| kind: Deployment | ||
| metadata: | ||
| name: nodejs-app | ||
| namespace: nodejs-ns | ||
| spec: | ||
| ... | ||
| template: | ||
| metadata: | ||
| ... | ||
| annotations: | ||
| instrumentation.opentelemetry.io/inject-nodejs: opentelemetry-operator-system/elastic-instrumentation | ||
| ... | ||
| ``` | ||
eedugon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - Alternatively, add the annotation at namespace level to apply auto-instrumentation in all Pods of the namespace: | ||
|
|
||
| ```bash | ||
| kubectl annotate namespace nodejs-ns instrumentation.opentelemetry.io/inject-nodejs=opentelemetry-operator-system/elastic-instrumentation | ||
| ``` | ||
|
|
||
| 3. Restart application | ||
|
|
||
| Once the annotation has been set, restart the application to create new Pods and inject the instrumentation libraries: | ||
|
|
||
| ```bash | ||
| kubectl rollout restart deployment nodejs-app -n nodejs-ns | ||
| ``` | ||
|
|
||
| 4. Verify the [auto-instrumentation resources](./instrumenting-applications.md#how-auto-instrumentation-works) are injected in the Pods: | ||
|
|
||
| Run a `kubectl describe` of one of your application Pods and check: | ||
|
|
||
| **REVIEW NEEDED HERE, it's a copy & paste from java SDK used as javaagent** | ||
| - There should be an init container named `opentelemetry-auto-instrumentation-nodejs` in the Pod: | ||
eedugon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```bash | ||
| $ kubectl describe pod nodejs-app-8d84c47b8-8h5z2 -n nodejs-ns | ||
| Name: nodejs-app-8d84c47b8-8h5z2 | ||
| Namespace: nodejs-ns | ||
| ... | ||
| ... | ||
| Init Containers: | ||
| opentelemetry-auto-instrumentation-nodejs: | ||
| Container ID: containerd://cbf67d7ca1bd62c25614b905a11e81405bed6fd215f2df21f84b90fd0279230b | ||
| Image: docker.elastic.co/observability/elastic-otel-nodejs:1.0.0 | ||
| Image ID: docker.elastic.co/observability/elastic-otel-nodejs@sha256:28d65d04a329c8d5545ed579d6c17f0d74800b7b1c5875e75e0efd29e210566a | ||
eedugon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Port: <none> | ||
| Host Port: <none> | ||
| Command: | ||
| cp | ||
| /nodejsagent.jar | ||
| /otel-auto-instrumentation-nodejs/nodejsagent.jar | ||
eedugon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| State: Terminated | ||
| Reason: Completed | ||
| Exit Code: 0 | ||
| Started: Wed, 13 Nov 2024 15:47:02 +0100 | ||
| Finished: Wed, 13 Nov 2024 15:47:03 +0100 | ||
| Ready: True | ||
| Restart Count: 0 | ||
| Environment: <none> | ||
| Mounts: | ||
| /otel-auto-instrumentation-nodejs from opentelemetry-auto-instrumentation-nodejs (rw) | ||
| /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-swhn5 (ro) | ||
| ``` | ||
| - The main container of the deployment is using the SDK as `nodejsagent`: | ||
| ```bash | ||
| ... | ||
| Containers: | ||
| nodejs-app: | ||
| Environment: | ||
| ... | ||
| JAVA_TOOL_OPTIONS: -nodejsagent:/otel-auto-instrumentation-nodejs/nodejsagent.jar | ||
| OTEL_SERVICE_NAME: nodejs-app | ||
eedugon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| OTEL_EXPORTER_OTLP_ENDPOINT: http://opentelemetry-kube-stack-daemon-collector.opentelemetry-operator-system.svc.cluster.local:4318 | ||
| ... | ||
| ``` | ||
| - The Pod has an `EmptyDir` volume named `opentelemetry-auto-instrumentation-nodejs` mounted in both the main and the init containers in path `/otel-auto-instrumentation-nodejs`. | ||
| ```bash | ||
| Init Containers: | ||
| opentelemetry-auto-instrumentation-nodejs: | ||
| ... | ||
| Mounts: | ||
| /otel-auto-instrumentation-nodejs from opentelemetry-auto-instrumentation-nodejs (rw) | ||
| Containers: | ||
| nodejs-app: | ||
| ... | ||
| Mounts: | ||
| /otel-auto-instrumentation-nodejs from opentelemetry-auto-instrumentation-nodejs (rw) | ||
| ... | ||
| Volumes: | ||
| ... | ||
| opentelemetry-auto-instrumentation-nodejs: | ||
| Type: EmptyDir (a temporary directory that shares a pod's lifetime) | ||
| ``` | ||
|
|
||
| Ensure the environment variable `OTEL_EXPORTER_OTLP_ENDPOINT` points to a valid endpoint and there's network communication between the Pod and the endpoint. | ||
eedugon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| **END OF REVIEW NEEDED SECTION** | ||
eedugon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 5. Confirm data is flowing to **Kibana**: | ||
| - Open **Observability** -> **Applications** -> **Service inventory**, and determine if: | ||
| - The application appears in the list of services (`nodejs-app` in the example). | ||
eedugon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - The application shows transactions and metrics. | ||
| - For application container logs, open **Kibana Discover** and filter for your Pods' logs. In the provided example, we could filter for them with either of the following: | ||
| - `k8s.deployment.name: "nodejs-app"` (**adapt the query filter to your use case**) | ||
| - `k8s.pod.name: nodejs-app*` (**adapt the query filter to your use case**) | ||
|
|
||
| Note that the container logs are not provided by the instrumentation library, but by the DaemonSet collector deployed as part of the [operator installation](./README.md). | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| - Refer to [troubleshoot auto-instrumentation](./troubleshoot-auto-instrumentation.md) for further analysis. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.