Skip to content
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

Add docker image containing nodejs auto instrumentation #508

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 44 additions & 0 deletions .github/workflows/publish-autoinstrumentation-nodejs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "Publish NodeJS Auto-Instrumentation"

on:
push:
paths:
- 'autoinstrumentation/nodejs/**'
- '.github/workflows/publish-autoinstrumentation-nodejs.yaml'
branches:
- main
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2.3.5

- name: Read version
run: echo VERSION=$(cat autoinstrumentation/nodejs/package.json | jq -r '.dependencies."@opentelemetry/sdk-node"') >> $GITHUB_ENV

- name: Docker meta
id: meta
uses: docker/metadata-action@v3.6.0
with:
images: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs
tags: |
type=match,pattern=v(.*),group=1,value=v${{ env.VERSION }}

- name: Login to GitHub Package Registry
uses: docker/login-action@v1.10.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2.7.0
with:
context: autoinstrumentation/nodejs
push: true
build-args: version=${{ env.VERSION }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ local
# test resources
kubeconfig
tests/_build/

# autoinstrumentation artifacts
build
node_modules
package-lock.json
2 changes: 2 additions & 0 deletions autoinstrumentation/nodejs/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
node_modules
10 changes: 10 additions & 0 deletions autoinstrumentation/nodejs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:16 AS build

WORKDIR /operator-build
COPY . .

RUN npm install

FROM busybox

COPY --from=build /operator-build/build/workspace /autoinstrumentation
22 changes: 22 additions & 0 deletions autoinstrumentation/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@opentelemetry/k8s-autoinstrumentation",
"version": "0.0.1",
"private": true,
"scripts": {
"clean": "rimraf build/*",
"prepare": "npm run compile",
"compile": "tsc -p .",
"postcompile": "copyfiles -f 'build/src/**' build/workspace/ && copyfiles 'node_modules/**' build/workspace/"
},
"devDependencies": {
"copyfiles": "^2.4.1",
"rimraf": "^3.0.2",
"typescript": "^4.4.4"
},
"dependencies": {
"@opentelemetry/api": "1.0.3",
"@opentelemetry/auto-instrumentations-node": "0.26.0",
"@opentelemetry/exporter-otlp-grpc": "0.26.0",
"@opentelemetry/sdk-node": "0.26.0"
}
}
12 changes: 12 additions & 0 deletions autoinstrumentation/nodejs/src/autoinstrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-otlp-grpc';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand NodeJS doesn't support env vars like OTEL_TRACES_EXPORTER yet. When it does, we would remove this sort of hard-coding.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an issue on this repository then?


import { NodeSDK } from '@opentelemetry/sdk-node';

const sdk = new NodeSDK({
autoDetectResources: true,
instrumentations: [getNodeAutoInstrumentations()],
traceExporter: new OTLPTraceExporter(),
});

sdk.start();
33 changes: 33 additions & 0 deletions autoinstrumentation/nodejs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"rootDir": ".",
"outDir": "build",

"allowUnreachableCode": false,
"allowUnusedLabels": false,
"composite": true,
"declaration": true,
"declarationMap": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"inlineSources": true,
"module": "commonjs",
"newLine": "LF",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"pretty": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"target": "es2017"
},
"include": [
"src/**/*.ts",
],
"exclude": [
"node_modules"
]
}
4 changes: 4 additions & 0 deletions versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ targetallocator=0.1.0
# Represents the current release of Java instrumentation.
# Should match autoinstrumentation/java/version.txt
autoinstrumentation-java=1.7.0

# Represents the current release of NodeJS instrumentation.
# Should match value in autoinstrumentation/nodejs/package.json
autoinstrumentation-nodejs=0.26.0