From b46331c5cc86298d32e4b6234f55b943a72ac548 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Wed, 22 Jan 2025 22:52:43 +0000 Subject: [PATCH 01/13] Add recipe showing use with self-managed OTLP ingest --- recipes/self-managed-otlp-ingest/README.md | 149 ++++++++++++++++++ .../instrumentation.yaml | 32 ++++ .../k8s/quickstart-app.yaml | 36 +++++ 3 files changed, 217 insertions(+) create mode 100644 recipes/self-managed-otlp-ingest/README.md create mode 100644 recipes/self-managed-otlp-ingest/instrumentation.yaml create mode 100644 recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml diff --git a/recipes/self-managed-otlp-ingest/README.md b/recipes/self-managed-otlp-ingest/README.md new file mode 100644 index 0000000..2864bf3 --- /dev/null +++ b/recipes/self-managed-otlp-ingest/README.md @@ -0,0 +1,149 @@ +# Using Self Managed OTLP ingest with OpenTelemetry Operator + +This recipe shows how to use self-managed OTLP ingest to export telemetry from an auto-instrumented application deployed on a GKE cluster. + +The example demonstrates a scenario where a user has an application deployed on a GKE cluster and now needs to instrument it and export the generated telemetry to Google Cloud. + +## Setting up the scenario + +> [!TIP] +> This section outlines the steps to create a cluster & deploy a sample application. Feel free to skip this section and move to [Instrumenting deployed applications](#instrumenting-deployed-applications) if you already have a sample app and cluster setup. + +### Creating a GKE cluster + +Run the following commands to create a GKE autopilot cluster. Alternatively, you can create a cluster using the Google Cloud Platform UI. + +```shell +# Setup required environment variables, modify based on your preference + +export PROJECT_ID="" +export CLUSTER_NAME="opentelemetry-autoinstrument-cluster" +export CLUSTER_REGION="us-central1" +``` + +The following `gcloud` command will begin the cluster creation process. +```shell +gcloud beta container --project "${PROJECT_ID}" clusters create-auto "${CLUSTER_NAME}" --region "${CLUSTER_REGION}" --release-channel "regular" --tier "standard" --enable-ip-access --no-enable-google-cloud-access --network "projects/${PROJECT_ID}/global/networks/default" --subnetwork "projects/${PROJECT_ID}/regions/${CLUSTER_REGION}/subnetworks/default" --cluster-ipv4-cidr "/17" --binauthz-evaluation-mode=DISABLED +``` + +Connect `kubectl` to the created cluster: +```shell +gcloud container clusters get-credentials ${CLUSTER_NAME} --region ${CLUSTER_REGION} --project ${PROJECT_ID} +``` + +### Deploy sample application (Java) on your cluster + +Deploy an un-instrumented application on your GKE cluster. The application used here is the un-instrumented version of the [Java Instrumentation Quickstart](https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/tree/main/examples/instrumentation-quickstart). + +To build the sample app, from the root of this recipe: +```shell +pushd uninstrumented-app/quickstart-java/examples/instrumentation-quickstart && \ +DOCKER_BUILDKIT=1 docker build -f uninstrumented.Dockerfile -t java-quickstart . && \ +popd +``` + +Next, push the locally built image to Google Artifact Registry: +```shell +# Export environment variables for configuring Artifact Registry +export CONTAINER_REGISTRY= +export REGISTRY_LOCATION=us-central1 + +# If you do not have an Artifact repository, make one: +gcloud artifacts repositories create ${CONTAINER_REGISTRY} --repository-format=docker --location=${REGISTRY_LOCATION} --description="Sample applications to auto-instrument using OTel operator" +# Alternatively, you can use any existing artifact registry + +docker tag java-quickstart:latest ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest +docker push ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest +``` + +Finally, deploy the pushed application in your cluster: +```shell +# This relies on the environment variables exported in previous steps +envsubst < k8s/quickstart-app.yaml | kubectl apply -f - +``` + +Once your application is deployed, you can interact with it by hitting either `/single` or `/multi` endpoints on port `8080`. For more information about the application, view the [application readme](uninstrumented-app/quickstart-java/examples/instrumentation-quickstart/README.md).\ +*Note: You may need to configure port forwarding to interact with this application over localhost.* + +## Instrumenting deployed applications + +Now that we have an application deployed on a GKE cluster, we can instrument the application using the OpenTelemetry operator. + +### Installing OpenTelemetry Operator + +We use the OpenTelemetry Operator to inject auto-instrumentation into the apps running in our cluster. +Follow [these steps](../../README.md#prerequisites) to ensure that `cert-manager` is installed on your cluster. + +```shell +# Install OpenTelemetry Operator +kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/download/v0.116.0/opentelemetry-operator.yaml +``` + +### Deploying a self-managed OpenTelemetry Collector on the cluster + +A self-managed OpenTelemetry Collector can be easily deployed by using scripts from [OTLP Kubernetes Ingest](https://github.com/GoogleCloudPlatform/otlp-k8s-ingest/tree/main) package: + +```shell +kubectl kustomize https://github.com/GoogleCloudPlatform/otlp-k8s-ingest/k8s/base | envsubst | kubectl apply -f - +``` + +This script creates a properly configured Collector with relevant permissions & recommended settings. + +> [!IMPORTANT] +> The following IAM permissions are required to be configured if you have enabled GKE Workload Identity Federation. This example uses GKE Autopilot, which has Workload Identity Federation enabled by default. +> It is necessary to configure Workload Identity to let the applications running in this cluster authenticate to Google Cloud APIs. + +For clusters with GKE Workload Identity Federation enabled, grant the deployed collector relevant IAM permissions: +```shell +# This is the number corresponding to your project ID, you can get this by visiting the Google Cloud Platform home page. +export PROJECT_NUMBER= + +gcloud projects add-iam-policy-binding projects/$PROJECT_ID \ + --role=roles/logging.logWriter \ + --member=principal://iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$PROJECT_ID.svc.id.goog/subject/ns/opentelemetry/sa/opentelemetry-collector \ + --condition=None +gcloud projects add-iam-policy-binding projects/$PROJECT_ID \ + --role=roles/monitoring.metricWriter \ + --member=principal://iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$PROJECT_ID.svc.id.goog/subject/ns/opentelemetry/sa/opentelemetry-collector \ + --condition=None +gcloud projects add-iam-policy-binding projects/$PROJECT_ID \ + --role=roles/cloudtrace.agent \ + --member=principal://iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$PROJECT_ID.svc.id.goog/subject/ns/opentelemetry/sa/opentelemetry-collector \ + --condition=None +``` + +At this point, there is an OpenTelemetry Collector running in the cluster and is ready to receive telemetry. + +### Injecting language specific auto-instrumentation + +Using the OpenTelemetry Operator, we can inject language specific auto-instrumentation in applications deployed in the cluster.\ +This is done by first creating the Instrumentation CRD (Custom Resource Definition) and then using annotations to apply the instrumentation to a specific Kubernetes resource. + +```shell +# Create the Instrumentation CRD +kubectl apply -f instrumentation.yaml +``` + +Next, annotate the deployment in which the created instrumentation needs to be injected: + +```shell +# Annotate the deployment to inject the created instrumentation +# This will trigger a rolling restart of the deployment +kubectl patch deployment.apps/quickstart-app -p '{"spec":{"template":{"metadata":{"annotations":{"instrumentation.opentelemetry.io/inject-java": "sample-java-auto-instrumentation"}}}}}' +``` + +## Viewing the result + +After injecting the application, the application should start producing telemetry which can be viewed in Google Cloud.\ +The instrumentation used in the sample is currently configured to generate only traces and the traces can be viewed on the GCP UI using the Trace Explorer. + +## Cleanup + +You can delete the cluster and the artifact registry created using this sample to avoid unnecessary charges: +```shell +# Delete the artifact registry +gcloud artifacts repositories delete ${CONTAINER_REGISTRY} --location=${REGISTRY_LOCATION} + +# Delete the cluster +gcloud container clusters delete ${CLUSTER_NAME} --location=${CLUSTER_REGION} +``` diff --git a/recipes/self-managed-otlp-ingest/instrumentation.yaml b/recipes/self-managed-otlp-ingest/instrumentation.yaml new file mode 100644 index 0000000..67f670c --- /dev/null +++ b/recipes/self-managed-otlp-ingest/instrumentation.yaml @@ -0,0 +1,32 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: Instrumentation +metadata: + namespace: default + name: sample-java-auto-instrumentation +spec: + exporter: + endpoint: http://otel-collector:4317 + propagators: + - tracecontext + - baggage + - b3 + sampler: + type: always_on + + java: + resources: + limits: + memory: 512Mi + requests: + memory: 512Mi + env: + - name: OTEL_EXPORTER_OTLP_PROTOCOL + value: grpc + - name: OTEL_METRICS_EXPORTER + value: none + - name: OTEL_LOGS_EXPORTER + value: none + - name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT + value: http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317 + - name: OTEL_EXPORTER_OTLP_COMPRESSION + value: gzip diff --git a/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml b/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml new file mode 100644 index 0000000..2232369 --- /dev/null +++ b/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml @@ -0,0 +1,36 @@ +apiVersion: v1 +kind: Service +metadata: + name: quickstart-app + labels: + app: quickstart-app +spec: + ports: + - port: 8080 + targetPort: 8080 + name: quickstart-app + selector: + app: quickstart-app +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: quickstart-app + labels: + app: quickstart-app +spec: + replicas: 3 + selector: + matchLabels: + app: quickstart-app + template: + metadata: + labels: + app: quickstart-app + spec: + containers: + - name: quickstart-app + image: ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest + ports: + - containerPort: 8080 + name: quickstart-app From 5cca955ca3ae703e90defa1337ae79b5ef9a2a13 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Wed, 22 Jan 2025 23:08:18 +0000 Subject: [PATCH 02/13] Add opentelemetry-operations-java as submodule to facilitate building sample app --- .gitmodules | 3 +++ .../uninstrumented-app/quickstart-java | 1 + recipes/self-managed-otlp-ingest/README.md | 4 ++-- recipes/self-managed-otlp-ingest/uninstrumented-app | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .gitmodules create mode 160000 recipes/recipes/self-managed-otlp-ingest/uninstrumented-app/quickstart-java create mode 160000 recipes/self-managed-otlp-ingest/uninstrumented-app diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4e850c4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "recipes/self-managed-otlp-ingest/uninstrumented-app"] + path = recipes/self-managed-otlp-ingest/uninstrumented-app + url = https://github.com/GoogleCloudPlatform/opentelemetry-operations-java.git diff --git a/recipes/recipes/self-managed-otlp-ingest/uninstrumented-app/quickstart-java b/recipes/recipes/self-managed-otlp-ingest/uninstrumented-app/quickstart-java new file mode 160000 index 0000000..404b12a --- /dev/null +++ b/recipes/recipes/self-managed-otlp-ingest/uninstrumented-app/quickstart-java @@ -0,0 +1 @@ +Subproject commit 404b12a72ca8e13b0b4809a476f31941bc0e5b60 diff --git a/recipes/self-managed-otlp-ingest/README.md b/recipes/self-managed-otlp-ingest/README.md index 2864bf3..604e55a 100644 --- a/recipes/self-managed-otlp-ingest/README.md +++ b/recipes/self-managed-otlp-ingest/README.md @@ -37,7 +37,7 @@ Deploy an un-instrumented application on your GKE cluster. The application used To build the sample app, from the root of this recipe: ```shell -pushd uninstrumented-app/quickstart-java/examples/instrumentation-quickstart && \ +pushd uninstrumented-app/examples/instrumentation-quickstart && \ DOCKER_BUILDKIT=1 docker build -f uninstrumented.Dockerfile -t java-quickstart . && \ popd ``` @@ -62,7 +62,7 @@ Finally, deploy the pushed application in your cluster: envsubst < k8s/quickstart-app.yaml | kubectl apply -f - ``` -Once your application is deployed, you can interact with it by hitting either `/single` or `/multi` endpoints on port `8080`. For more information about the application, view the [application readme](uninstrumented-app/quickstart-java/examples/instrumentation-quickstart/README.md).\ +Once your application is deployed, you can interact with it by hitting either `/single` or `/multi` endpoints on port `8080`. For more information about the application, view the [application readme](uninstrumented-app/examples/instrumentation-quickstart/README.md).\ *Note: You may need to configure port forwarding to interact with this application over localhost.* ## Instrumenting deployed applications diff --git a/recipes/self-managed-otlp-ingest/uninstrumented-app b/recipes/self-managed-otlp-ingest/uninstrumented-app new file mode 160000 index 0000000..404b12a --- /dev/null +++ b/recipes/self-managed-otlp-ingest/uninstrumented-app @@ -0,0 +1 @@ +Subproject commit 404b12a72ca8e13b0b4809a476f31941bc0e5b60 From 3975c9c5018b2c69b8ca568c52b9ee3976285106 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Thu, 23 Jan 2025 00:01:54 +0000 Subject: [PATCH 03/13] Add copyright headers --- .../self-managed-otlp-ingest/instrumentation.yaml | 14 ++++++++++++++ .../k8s/quickstart-app.yaml | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/recipes/self-managed-otlp-ingest/instrumentation.yaml b/recipes/self-managed-otlp-ingest/instrumentation.yaml index 67f670c..50a5609 100644 --- a/recipes/self-managed-otlp-ingest/instrumentation.yaml +++ b/recipes/self-managed-otlp-ingest/instrumentation.yaml @@ -1,3 +1,17 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + apiVersion: opentelemetry.io/v1alpha1 kind: Instrumentation metadata: diff --git a/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml b/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml index 2232369..39e788a 100644 --- a/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml +++ b/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml @@ -1,3 +1,17 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + apiVersion: v1 kind: Service metadata: From f184b5e1b3ea41719418aeb6b169bb4a78c034e2 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Thu, 23 Jan 2025 00:25:20 +0000 Subject: [PATCH 04/13] Add convinience script to create cluster with deployed app --- recipes/self-managed-otlp-ingest/README.md | 7 ++- .../setup-application.sh | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100755 recipes/self-managed-otlp-ingest/setup-application.sh diff --git a/recipes/self-managed-otlp-ingest/README.md b/recipes/self-managed-otlp-ingest/README.md index 604e55a..9117408 100644 --- a/recipes/self-managed-otlp-ingest/README.md +++ b/recipes/self-managed-otlp-ingest/README.md @@ -4,10 +4,11 @@ This recipe shows how to use self-managed OTLP ingest to export telemetry from a The example demonstrates a scenario where a user has an application deployed on a GKE cluster and now needs to instrument it and export the generated telemetry to Google Cloud. -## Setting up the scenario +## Setting up the cluster with an application > [!TIP] > This section outlines the steps to create a cluster & deploy a sample application. Feel free to skip this section and move to [Instrumenting deployed applications](#instrumenting-deployed-applications) if you already have a sample app and cluster setup. +> Alternatively, you can run a convenience script that executes the steps in this section to give you a cluster with a running application. You can execute this script from the root of this recipe: `./setup-application.sh`. ### Creating a GKE cluster @@ -141,9 +142,7 @@ The instrumentation used in the sample is currently configured to generate only You can delete the cluster and the artifact registry created using this sample to avoid unnecessary charges: ```shell -# Delete the artifact registry +# Delete the artifact registry & the created cluster gcloud artifacts repositories delete ${CONTAINER_REGISTRY} --location=${REGISTRY_LOCATION} - -# Delete the cluster gcloud container clusters delete ${CLUSTER_NAME} --location=${CLUSTER_REGION} ``` diff --git a/recipes/self-managed-otlp-ingest/setup-application.sh b/recipes/self-managed-otlp-ingest/setup-application.sh new file mode 100755 index 0000000..11dc256 --- /dev/null +++ b/recipes/self-managed-otlp-ingest/setup-application.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +UNSET_WARNING="Environment variable not set, please set the environment variable" + +# Verify necessary environment variables are set +echo "${PROJECT_ID:?${UNSET_WARNING}}" +echo "${CLUSTER_NAME:?${UNSET_WARNING}}" +echo "${CLUSTER_REGION:?${UNSET_WARNING}}" +echo "${CONTAINER_REGISTRY:?${UNSET_WARNING}}" +echo "${REGISTRY_LOCATION:?${UNSET_WARNING}}" + +echo "ENVIRONMENT VARIABLES VERIFIED" + +echo "CREATING CLUSTER WITH NAME ${CLUSTER_NAME} in ${CLUSTER_REGION}" +gcloud beta container --project "${PROJECT_ID}" clusters create-auto "${CLUSTER_NAME}" --region "${CLUSTER_REGION}" --release-channel "regular" --tier "standard" --enable-ip-access --no-enable-google-cloud-access --network "projects/${PROJECT_ID}/global/networks/default" --subnetwork "projects/${PROJECT_ID}/regions/${CLUSTER_REGION}/subnetworks/default" --cluster-ipv4-cidr "/17" --binauthz-evaluation-mode=DISABLED +echo "CLUSTER CREATED SUCCESSFULLY" + +echo "BUILDING SAMPLE APPLICATION IMAGE" +pushd uninstrumented-app/examples/instrumentation-quickstart && \ +DOCKER_BUILDKIT=1 docker build -f uninstrumented.Dockerfile -t java-quickstart . && \ +popd +echo "APPLICATION IMAGE BUILT" + +echo "CREATING CLOUD ARTIFACT REPOSITORY" +gcloud artifacts repositories create ${CONTAINER_REGISTRY} --repository-format=docker --location=${REGISTRY_LOCATION} --description="Sample applications to auto-instrument using OTel operator" +echo "CREATED ${CONTAINER_REGISTRY} in ${REGISTRY_LOCATION}" + +echo "PUSHING THE SAMPLE APPLICATION IMAGE TO THE REPOSITORY" +docker tag java-quickstart:latest ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest +docker push ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest +echo "APPLICATION IMAGE PUSHED TO ARTIFACT REPOSITORY" + +echo "DEPLOYING SAMPLE APPLICATION ON ${CLUSTER_NAME}" +envsubst < k8s/quickstart-app.yaml | kubectl apply -f - +echo "SAMPLE APPLICATION DEPLOYED" From 625b85075a4f7a36c3b2c770b49d574494be2f6b Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Thu, 23 Jan 2025 17:13:09 +0000 Subject: [PATCH 05/13] Remove the use of submodules --- .gitmodules | 3 --- .../uninstrumented-app/quickstart-java | 1 - recipes/self-managed-otlp-ingest/README.md | 10 ++++++---- recipes/self-managed-otlp-ingest/setup-application.sh | 7 +++++-- recipes/self-managed-otlp-ingest/uninstrumented-app | 1 - 5 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 .gitmodules delete mode 160000 recipes/recipes/self-managed-otlp-ingest/uninstrumented-app/quickstart-java delete mode 160000 recipes/self-managed-otlp-ingest/uninstrumented-app diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 4e850c4..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "recipes/self-managed-otlp-ingest/uninstrumented-app"] - path = recipes/self-managed-otlp-ingest/uninstrumented-app - url = https://github.com/GoogleCloudPlatform/opentelemetry-operations-java.git diff --git a/recipes/recipes/self-managed-otlp-ingest/uninstrumented-app/quickstart-java b/recipes/recipes/self-managed-otlp-ingest/uninstrumented-app/quickstart-java deleted file mode 160000 index 404b12a..0000000 --- a/recipes/recipes/self-managed-otlp-ingest/uninstrumented-app/quickstart-java +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 404b12a72ca8e13b0b4809a476f31941bc0e5b60 diff --git a/recipes/self-managed-otlp-ingest/README.md b/recipes/self-managed-otlp-ingest/README.md index 9117408..a351916 100644 --- a/recipes/self-managed-otlp-ingest/README.md +++ b/recipes/self-managed-otlp-ingest/README.md @@ -7,7 +7,7 @@ The example demonstrates a scenario where a user has an application deployed on ## Setting up the cluster with an application > [!TIP] -> This section outlines the steps to create a cluster & deploy a sample application. Feel free to skip this section and move to [Instrumenting deployed applications](#instrumenting-deployed-applications) if you already have a sample app and cluster setup. +> This section outlines the steps to create a cluster & deploy a sample application. Feel free to skip this section and move to [Instrumenting deployed applications](#instrumenting-deployed-applications) if you already have a sample app and cluster setup. \ > Alternatively, you can run a convenience script that executes the steps in this section to give you a cluster with a running application. You can execute this script from the root of this recipe: `./setup-application.sh`. ### Creating a GKE cluster @@ -16,7 +16,6 @@ Run the following commands to create a GKE autopilot cluster. Alternatively, you ```shell # Setup required environment variables, modify based on your preference - export PROJECT_ID="" export CLUSTER_NAME="opentelemetry-autoinstrument-cluster" export CLUSTER_REGION="us-central1" @@ -38,9 +37,12 @@ Deploy an un-instrumented application on your GKE cluster. The application used To build the sample app, from the root of this recipe: ```shell -pushd uninstrumented-app/examples/instrumentation-quickstart && \ +# We pull the application from GitHub and build it +git clone https://github.com/GoogleCloudPlatform/opentelemetry-operations-java.git +pushd opentelemetry-operations-java/examples/instrumentation-quickstart && \ DOCKER_BUILDKIT=1 docker build -f uninstrumented.Dockerfile -t java-quickstart . && \ -popd +popd && \ +rm -rf opentelemetry-operations-java ``` Next, push the locally built image to Google Artifact Registry: diff --git a/recipes/self-managed-otlp-ingest/setup-application.sh b/recipes/self-managed-otlp-ingest/setup-application.sh index 11dc256..ff2d96d 100755 --- a/recipes/self-managed-otlp-ingest/setup-application.sh +++ b/recipes/self-managed-otlp-ingest/setup-application.sh @@ -28,10 +28,13 @@ echo "CREATING CLUSTER WITH NAME ${CLUSTER_NAME} in ${CLUSTER_REGION}" gcloud beta container --project "${PROJECT_ID}" clusters create-auto "${CLUSTER_NAME}" --region "${CLUSTER_REGION}" --release-channel "regular" --tier "standard" --enable-ip-access --no-enable-google-cloud-access --network "projects/${PROJECT_ID}/global/networks/default" --subnetwork "projects/${PROJECT_ID}/regions/${CLUSTER_REGION}/subnetworks/default" --cluster-ipv4-cidr "/17" --binauthz-evaluation-mode=DISABLED echo "CLUSTER CREATED SUCCESSFULLY" +echo "PULLING SAMPLE APPLICATION REPOSITORY" echo "BUILDING SAMPLE APPLICATION IMAGE" -pushd uninstrumented-app/examples/instrumentation-quickstart && \ +git clone https://github.com/GoogleCloudPlatform/opentelemetry-operations-java.git +pushd opentelemetry-operations-java/examples/instrumentation-quickstart && \ DOCKER_BUILDKIT=1 docker build -f uninstrumented.Dockerfile -t java-quickstart . && \ -popd +popd && \ +rm -rf opentelemetry-operations-java echo "APPLICATION IMAGE BUILT" echo "CREATING CLOUD ARTIFACT REPOSITORY" diff --git a/recipes/self-managed-otlp-ingest/uninstrumented-app b/recipes/self-managed-otlp-ingest/uninstrumented-app deleted file mode 160000 index 404b12a..0000000 --- a/recipes/self-managed-otlp-ingest/uninstrumented-app +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 404b12a72ca8e13b0b4809a476f31941bc0e5b60 From 6ca4355ee25daac75b664bd0a698377ff09a6a31 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Fri, 24 Jan 2025 19:57:21 +0000 Subject: [PATCH 06/13] Address comments on README --- recipes/self-managed-otlp-ingest/README.md | 81 +++++++++++++--------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/recipes/self-managed-otlp-ingest/README.md b/recipes/self-managed-otlp-ingest/README.md index a351916..6100ce4 100644 --- a/recipes/self-managed-otlp-ingest/README.md +++ b/recipes/self-managed-otlp-ingest/README.md @@ -23,7 +23,7 @@ export CLUSTER_REGION="us-central1" The following `gcloud` command will begin the cluster creation process. ```shell -gcloud beta container --project "${PROJECT_ID}" clusters create-auto "${CLUSTER_NAME}" --region "${CLUSTER_REGION}" --release-channel "regular" --tier "standard" --enable-ip-access --no-enable-google-cloud-access --network "projects/${PROJECT_ID}/global/networks/default" --subnetwork "projects/${PROJECT_ID}/regions/${CLUSTER_REGION}/subnetworks/default" --cluster-ipv4-cidr "/17" --binauthz-evaluation-mode=DISABLED +gcloud beta container --project "${PROJECT_ID}" clusters create-auto "${CLUSTER_NAME}" --region "${CLUSTER_REGION}" ``` Connect `kubectl` to the created cluster: @@ -51,10 +51,11 @@ Next, push the locally built image to Google Artifact Registry: export CONTAINER_REGISTRY= export REGISTRY_LOCATION=us-central1 -# If you do not have an Artifact repository, make one: -gcloud artifacts repositories create ${CONTAINER_REGISTRY} --repository-format=docker --location=${REGISTRY_LOCATION} --description="Sample applications to auto-instrument using OTel operator" +# If you do not have an Artifact repository, make one. # Alternatively, you can use any existing artifact registry +gcloud artifacts repositories create ${CONTAINER_REGISTRY} --repository-format=docker --location=${REGISTRY_LOCATION} --description="Sample applications to auto-instrument using OTel operator" +# Tag and push the built application image to Google Artifact Registry docker tag java-quickstart:latest ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest docker push ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest ``` @@ -68,35 +69,16 @@ envsubst < k8s/quickstart-app.yaml | kubectl apply -f - Once your application is deployed, you can interact with it by hitting either `/single` or `/multi` endpoints on port `8080`. For more information about the application, view the [application readme](uninstrumented-app/examples/instrumentation-quickstart/README.md).\ *Note: You may need to configure port forwarding to interact with this application over localhost.* -## Instrumenting deployed applications - -Now that we have an application deployed on a GKE cluster, we can instrument the application using the OpenTelemetry operator. - -### Installing OpenTelemetry Operator +## Deploy a self-managed OpenTelemetry Collector on the cluster -We use the OpenTelemetry Operator to inject auto-instrumentation into the apps running in our cluster. -Follow [these steps](../../README.md#prerequisites) to ensure that `cert-manager` is installed on your cluster. - -```shell -# Install OpenTelemetry Operator -kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/download/v0.116.0/opentelemetry-operator.yaml -``` - -### Deploying a self-managed OpenTelemetry Collector on the cluster - -A self-managed OpenTelemetry Collector can be easily deployed by using scripts from [OTLP Kubernetes Ingest](https://github.com/GoogleCloudPlatform/otlp-k8s-ingest/tree/main) package: - -```shell -kubectl kustomize https://github.com/GoogleCloudPlatform/otlp-k8s-ingest/k8s/base | envsubst | kubectl apply -f - -``` - -This script creates a properly configured Collector with relevant permissions & recommended settings. +This step deploys an [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector) instance in the created cluster. +Our application will then be configured to send telemetry to this collector instance and the collector will export the generated telemetry to Google Cloud. > [!IMPORTANT] > The following IAM permissions are required to be configured if you have enabled GKE Workload Identity Federation. This example uses GKE Autopilot, which has Workload Identity Federation enabled by default. -> It is necessary to configure Workload Identity to let the applications running in this cluster authenticate to Google Cloud APIs. +> It is necessary to configure Workload Identity to let the applications running in this cluster authenticate to Google Cloud APIs. The collector that will be deployed in this cluster will require these permissions -For clusters with GKE Workload Identity Federation enabled, grant the deployed collector relevant IAM permissions: +For clusters with GKE Workload Identity Federation enabled, grant the relevant IAM permissions: ```shell # This is the number corresponding to your project ID, you can get this by visiting the Google Cloud Platform home page. export PROJECT_NUMBER= @@ -114,8 +96,42 @@ gcloud projects add-iam-policy-binding projects/$PROJECT_ID \ --member=principal://iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$PROJECT_ID.svc.id.goog/subject/ns/opentelemetry/sa/opentelemetry-collector \ --condition=None ``` +*Note: The permissions are being granted to a service account in a given namespace within the cluster. The collector deployment will be configured to use the same service account and namespace.* -At this point, there is an OpenTelemetry Collector running in the cluster and is ready to receive telemetry. +A self-managed OpenTelemetry Collector can be easily deployed by using scripts from [OTLP Kubernetes Ingest](https://github.com/GoogleCloudPlatform/otlp-k8s-ingest/tree/main) package: + +```shell +kubectl kustomize https://github.com/GoogleCloudPlatform/otlp-k8s-ingest/k8s/base | envsubst | kubectl apply -f - +``` + +This script creates a properly configured Collector with relevant permissions & recommended settings. \ +At this point, there is an OpenTelemetry Collector instance running in the cluster that is ready to receive & export telemetry. + +## Instrumenting deployed applications + +Now that we have an application deployed on a GKE cluster & an OpenTelemetry Collector instance configured to receive telemetry, we can instrument the application using the OpenTelemetry operator. + +### Installing OpenTelemetry Operator + +We use the OpenTelemetry Operator to inject auto-instrumentation into the apps running in our cluster.\ +For GKE Autopilot, install `cert-manager` with the following [Helm](https://helm.sh) commands: +```shell +helm repo add jetstack https://charts.jetstack.io +helm repo update +helm install \ +--create-namespace \ +--namespace cert-manager \ +--set installCRDs=true \ +--set global.leaderElection.namespace=cert-manager \ +--set extraArgs={--issuer-ambient-credentials=true} \ +cert-manager jetstack/cert-manager +``` + +Install OpenTelemetry Operator with the following command: +```shell +# Install OpenTelemetry Operator +kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/download/v0.116.0/opentelemetry-operator.yaml +``` ### Injecting language specific auto-instrumentation @@ -132,7 +148,10 @@ Next, annotate the deployment in which the created instrumentation needs to be i ```shell # Annotate the deployment to inject the created instrumentation # This will trigger a rolling restart of the deployment -kubectl patch deployment.apps/quickstart-app -p '{"spec":{"template":{"metadata":{"annotations":{"instrumentation.opentelemetry.io/inject-java": "sample-java-auto-instrumentation"}}}}}' +kubectl patch deployment.apps/quickstart-app -n default -p '{"spec":{"template":{"metadata":{"annotations":{"instrumentation.opentelemetry.io/inject-java": "default/sample-java-auto-instrumentation"}}}}}' + +# This sample shows both instrumentation and application deployment in the default namespace. +# However, they could be deployed in separate namespaces as well. ``` ## Viewing the result @@ -144,7 +163,7 @@ The instrumentation used in the sample is currently configured to generate only You can delete the cluster and the artifact registry created using this sample to avoid unnecessary charges: ```shell -# Delete the artifact registry & the created cluster -gcloud artifacts repositories delete ${CONTAINER_REGISTRY} --location=${REGISTRY_LOCATION} +# Delete the created cluster & the artifact registry gcloud container clusters delete ${CLUSTER_NAME} --location=${CLUSTER_REGION} +gcloud artifacts repositories delete ${CONTAINER_REGISTRY} --location=${REGISTRY_LOCATION} ``` From 52d58fe1ffb5e4c1baa75969612e5ad39c176ea8 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Fri, 24 Jan 2025 22:47:04 +0000 Subject: [PATCH 07/13] Update number of replicas --- recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml b/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml index 39e788a..71bf62e 100644 --- a/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml +++ b/recipes/self-managed-otlp-ingest/k8s/quickstart-app.yaml @@ -33,7 +33,7 @@ metadata: labels: app: quickstart-app spec: - replicas: 3 + replicas: 2 selector: matchLabels: app: quickstart-app From 8aa29d1c8076b9f0caf724b8d184676290c1bff3 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Fri, 24 Jan 2025 22:52:28 +0000 Subject: [PATCH 08/13] Simplify the command to create the cluster --- recipes/self-managed-otlp-ingest/setup-application.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/self-managed-otlp-ingest/setup-application.sh b/recipes/self-managed-otlp-ingest/setup-application.sh index ff2d96d..7ebe650 100755 --- a/recipes/self-managed-otlp-ingest/setup-application.sh +++ b/recipes/self-managed-otlp-ingest/setup-application.sh @@ -25,7 +25,7 @@ echo "${REGISTRY_LOCATION:?${UNSET_WARNING}}" echo "ENVIRONMENT VARIABLES VERIFIED" echo "CREATING CLUSTER WITH NAME ${CLUSTER_NAME} in ${CLUSTER_REGION}" -gcloud beta container --project "${PROJECT_ID}" clusters create-auto "${CLUSTER_NAME}" --region "${CLUSTER_REGION}" --release-channel "regular" --tier "standard" --enable-ip-access --no-enable-google-cloud-access --network "projects/${PROJECT_ID}/global/networks/default" --subnetwork "projects/${PROJECT_ID}/regions/${CLUSTER_REGION}/subnetworks/default" --cluster-ipv4-cidr "/17" --binauthz-evaluation-mode=DISABLED +gcloud beta container --project "${PROJECT_ID}" clusters create-auto "${CLUSTER_NAME}" --region "${CLUSTER_REGION}" echo "CLUSTER CREATED SUCCESSFULLY" echo "PULLING SAMPLE APPLICATION REPOSITORY" From 2e46e9dc46bcf8722f4c1f518443bd5a08091aaf Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Sat, 25 Jan 2025 18:58:12 +0000 Subject: [PATCH 09/13] Simplify the instrumentation config Updates the instrumentation to rely more on the defaults --- .../self-managed-otlp-ingest/instrumentation.yaml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/recipes/self-managed-otlp-ingest/instrumentation.yaml b/recipes/self-managed-otlp-ingest/instrumentation.yaml index 50a5609..4c8b829 100644 --- a/recipes/self-managed-otlp-ingest/instrumentation.yaml +++ b/recipes/self-managed-otlp-ingest/instrumentation.yaml @@ -18,29 +18,19 @@ metadata: namespace: default name: sample-java-auto-instrumentation spec: - exporter: - endpoint: http://otel-collector:4317 propagators: - tracecontext - baggage - b3 sampler: - type: always_on + type: parentbased_traceidratio + argument: "0.01" java: - resources: - limits: - memory: 512Mi - requests: - memory: 512Mi env: - - name: OTEL_EXPORTER_OTLP_PROTOCOL - value: grpc - name: OTEL_METRICS_EXPORTER value: none - name: OTEL_LOGS_EXPORTER value: none - name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT value: http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317 - - name: OTEL_EXPORTER_OTLP_COMPRESSION - value: gzip From fdfad6c2fdb641f900338f4f8b6520fe9c23cf71 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Sat, 25 Jan 2025 19:03:20 +0000 Subject: [PATCH 10/13] Add a traffic generator that simulates traffic The generated traffic results in telemetry being produced from the application. --- recipes/self-managed-otlp-ingest/README.md | 13 ++++--- .../k8s/kustomization.yaml | 19 ++++++++++ .../k8s/quickstart-traffic.yaml | 36 +++++++++++++++++++ .../setup-application.sh | 17 ++++++--- .../traffic/hey.Dockerfile | 24 +++++++++++++ 5 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 recipes/self-managed-otlp-ingest/k8s/kustomization.yaml create mode 100644 recipes/self-managed-otlp-ingest/k8s/quickstart-traffic.yaml create mode 100644 recipes/self-managed-otlp-ingest/traffic/hey.Dockerfile diff --git a/recipes/self-managed-otlp-ingest/README.md b/recipes/self-managed-otlp-ingest/README.md index 6100ce4..1cfeda8 100644 --- a/recipes/self-managed-otlp-ingest/README.md +++ b/recipes/self-managed-otlp-ingest/README.md @@ -58,16 +58,21 @@ gcloud artifacts repositories create ${CONTAINER_REGISTRY} --repository-format=d # Tag and push the built application image to Google Artifact Registry docker tag java-quickstart:latest ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest docker push ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest + +# Additionally, we build a docker image that can simulate traffic on the deployed application by sending requests to our application +pushd traffic && \ +DOCKER_BUILDKIT=1 docker build -f hey.Dockerfile -t ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/hey:latest . && \ +docker push ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/hey:latest && \ +popd ``` -Finally, deploy the pushed application in your cluster: +Finally, deploy the pushed application & traffic generator in your cluster: ```shell # This relies on the environment variables exported in previous steps -envsubst < k8s/quickstart-app.yaml | kubectl apply -f - +kubectl kustomize k8s | envsubst | kubectl apply -f - ``` -Once your application is deployed, you can interact with it by hitting either `/single` or `/multi` endpoints on port `8080`. For more information about the application, view the [application readme](uninstrumented-app/examples/instrumentation-quickstart/README.md).\ -*Note: You may need to configure port forwarding to interact with this application over localhost.* +The traffic generator simulates traffic on the deployed endpoint by hitting the `/multi` endpoint at 1 QPS. For more information about the application, view the [application readme](uninstrumented-app/examples/instrumentation-quickstart/README.md).\ ## Deploy a self-managed OpenTelemetry Collector on the cluster diff --git a/recipes/self-managed-otlp-ingest/k8s/kustomization.yaml b/recipes/self-managed-otlp-ingest/k8s/kustomization.yaml new file mode 100644 index 0000000..465febb --- /dev/null +++ b/recipes/self-managed-otlp-ingest/k8s/kustomization.yaml @@ -0,0 +1,19 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- quickstart-app.yaml +- quickstart-traffic.yaml diff --git a/recipes/self-managed-otlp-ingest/k8s/quickstart-traffic.yaml b/recipes/self-managed-otlp-ingest/k8s/quickstart-traffic.yaml new file mode 100644 index 0000000..4147f00 --- /dev/null +++ b/recipes/self-managed-otlp-ingest/k8s/quickstart-traffic.yaml @@ -0,0 +1,36 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: traffic-simulator +spec: + replicas: 1 + selector: + matchLabels: + app: traffic-simulator + template: + metadata: + labels: + app: traffic-simulator + spec: + containers: + - name: traffic-simulator + image: ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/hey:latest + args: + - -c=2 + - -q=1 + - -z=1h + - http://quickstart-app:8080/multi diff --git a/recipes/self-managed-otlp-ingest/setup-application.sh b/recipes/self-managed-otlp-ingest/setup-application.sh index 7ebe650..6dc4ef6 100755 --- a/recipes/self-managed-otlp-ingest/setup-application.sh +++ b/recipes/self-managed-otlp-ingest/setup-application.sh @@ -37,15 +37,22 @@ popd && \ rm -rf opentelemetry-operations-java echo "APPLICATION IMAGE BUILT" -echo "CREATING CLOUD ARTIFACT REPOSITORY" +echo "CREATING CLOUD ARTIFACT REGISTRY" gcloud artifacts repositories create ${CONTAINER_REGISTRY} --repository-format=docker --location=${REGISTRY_LOCATION} --description="Sample applications to auto-instrument using OTel operator" echo "CREATED ${CONTAINER_REGISTRY} in ${REGISTRY_LOCATION}" -echo "PUSHING THE SAMPLE APPLICATION IMAGE TO THE REPOSITORY" +echo "PUSHING THE SAMPLE APPLICATION IMAGE TO THE REGISTRY" docker tag java-quickstart:latest ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest docker push ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/java-quickstart:latest -echo "APPLICATION IMAGE PUSHED TO ARTIFACT REPOSITORY" +echo "APPLICATION IMAGE PUSHED TO ARTIFACT REGISTRY" -echo "DEPLOYING SAMPLE APPLICATION ON ${CLUSTER_NAME}" -envsubst < k8s/quickstart-app.yaml | kubectl apply -f - +echo "BUILDING TRAFFIC SIMULATOR IMAGE" +pushd traffic && \ +DOCKER_BUILDKIT=1 docker build -f hey.Dockerfile -t ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/hey:latest . && \ +docker push ${REGISTRY_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${CONTAINER_REGISTRY}/hey:latest && \ +popd +echo "TRAFFIC SIMULATOR IMAGE BUILT & PUSHED TO ARTIFACT REGISTRY" + +echo "DEPLOYING APPLICATION ON ${CLUSTER_NAME}" +kubectl kustomize k8s | envsubst | kubectl apply -f - echo "SAMPLE APPLICATION DEPLOYED" diff --git a/recipes/self-managed-otlp-ingest/traffic/hey.Dockerfile b/recipes/self-managed-otlp-ingest/traffic/hey.Dockerfile new file mode 100644 index 0000000..9c855be --- /dev/null +++ b/recipes/self-managed-otlp-ingest/traffic/hey.Dockerfile @@ -0,0 +1,24 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM golang:1.21-alpine3.19 AS build + +RUN apk add --no-cache wget +RUN wget -O /hey https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64 +RUN chmod +x /hey + +FROM scratch +COPY --from=build /hey /hey + +ENTRYPOINT ["/hey"] From 7f1fd1a9010d14b20dda1034ef9d917811f7c21f Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Sun, 26 Jan 2025 23:59:55 +0000 Subject: [PATCH 11/13] Add metrics export --- recipes/self-managed-otlp-ingest/instrumentation.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/recipes/self-managed-otlp-ingest/instrumentation.yaml b/recipes/self-managed-otlp-ingest/instrumentation.yaml index 4c8b829..5311fa0 100644 --- a/recipes/self-managed-otlp-ingest/instrumentation.yaml +++ b/recipes/self-managed-otlp-ingest/instrumentation.yaml @@ -28,9 +28,11 @@ spec: java: env: - - name: OTEL_METRICS_EXPORTER - value: none + - name: OTEL_EXPORTER_OTLP_PROTOCOL + value: grpc - name: OTEL_LOGS_EXPORTER value: none + - name: OTEL_EXPORTER_OTLP_METRICS_ENDPOINT + value: http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317 - name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT value: http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317 From 8f49302ea1d41b894b8eb9cf20bb9537a862f82a Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Mon, 27 Jan 2025 22:07:39 +0000 Subject: [PATCH 12/13] Update README add information about metrics --- recipes/self-managed-otlp-ingest/README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/recipes/self-managed-otlp-ingest/README.md b/recipes/self-managed-otlp-ingest/README.md index 1cfeda8..84ab926 100644 --- a/recipes/self-managed-otlp-ingest/README.md +++ b/recipes/self-managed-otlp-ingest/README.md @@ -1,9 +1,13 @@ # Using Self Managed OTLP ingest with OpenTelemetry Operator -This recipe shows how to use self-managed OTLP ingest to export telemetry from an auto-instrumented application deployed on a GKE cluster. - +This recipe shows how to use self-managed OTLP ingest to export telemetry from an auto-instrumented application deployed on a GKE cluster. \ The example demonstrates a scenario where a user has an application deployed on a GKE cluster and now needs to instrument it and export the generated telemetry to Google Cloud. +There are three broad steps that give the overview for this recipe: +1. [Running a GKE cluster with a deployed Java application](#setting-up-the-cluster-with-an-application) +2. [Deploying a self-managed OpenTelemetry Collector](#deploy-a-self-managed-opentelemetry-collector-on-the-cluster) +3. [Auto-instrumenting the deployed Java application](#instrumenting-deployed-applications) + ## Setting up the cluster with an application > [!TIP] @@ -162,7 +166,14 @@ kubectl patch deployment.apps/quickstart-app -n default -p '{"spec":{"template": ## Viewing the result After injecting the application, the application should start producing telemetry which can be viewed in Google Cloud.\ -The instrumentation used in the sample is currently configured to generate only traces and the traces can be viewed on the GCP UI using the Trace Explorer. +The instrumentation used in the sample is currently configured to generate traces and the traces and metrics. + - The traces can be viewed visiting the [trace explorer page](https://cloud.google.com/trace/docs/finding-traces#about) in your project. + - The metrics can be viewed visiting the [metrics explorer page](https://console.cloud.google.com/monitoring/metrics-explorer) in your project. + +The metrics are exported using [Google managed service for Prometheus](https://cloud.google.com/stackdriver/docs/managed-prometheus) and will have `prometheus.googleapis.com` as their metric prefix. + +If the expected metrics are not visible, please check the collector logs for any potential errors. +Troubleshooting information for known error types is available [here](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/googlemanagedprometheusexporter#troubleshooting). ## Cleanup From 8338b98201edaf274ac0816e604178d913a6cfcd Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Tue, 28 Jan 2025 18:28:45 +0000 Subject: [PATCH 13/13] Address comments & simplify the instrumentation --- recipes/self-managed-otlp-ingest/instrumentation.yaml | 10 ++-------- .../self-managed-otlp-ingest/traffic/hey.Dockerfile | 2 ++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/recipes/self-managed-otlp-ingest/instrumentation.yaml b/recipes/self-managed-otlp-ingest/instrumentation.yaml index 5311fa0..e438aee 100644 --- a/recipes/self-managed-otlp-ingest/instrumentation.yaml +++ b/recipes/self-managed-otlp-ingest/instrumentation.yaml @@ -18,10 +18,8 @@ metadata: namespace: default name: sample-java-auto-instrumentation spec: - propagators: - - tracecontext - - baggage - - b3 + exporter: + endpoint: http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317 sampler: type: parentbased_traceidratio argument: "0.01" @@ -32,7 +30,3 @@ spec: value: grpc - name: OTEL_LOGS_EXPORTER value: none - - name: OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - value: http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317 - - name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT - value: http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317 diff --git a/recipes/self-managed-otlp-ingest/traffic/hey.Dockerfile b/recipes/self-managed-otlp-ingest/traffic/hey.Dockerfile index 9c855be..2d5f169 100644 --- a/recipes/self-managed-otlp-ingest/traffic/hey.Dockerfile +++ b/recipes/self-managed-otlp-ingest/traffic/hey.Dockerfile @@ -15,6 +15,8 @@ FROM golang:1.21-alpine3.19 AS build RUN apk add --no-cache wget +# The link for the binary is specified in library's README +# https://github.com/rakyll/hey/blob/master/README.md RUN wget -O /hey https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64 RUN chmod +x /hey