Skip to content

Commit

Permalink
chore: Update deprecations in instrumentation-express/examples (#1842)
Browse files Browse the repository at this point in the history
* chore: Update express example package.json since it moved repos

This must have moved into contrib a while back

* docs: Modify the install command so that the example runs

Without this, 'npm install' now depends on directories higher than this one.
It does not create a node_modules
and then ts-node does not work.

Looks like the use of workspaces at the repository root interferes with this example,
but this change to the install command gets around that.

* chore: Update instrumentation-express example otel packages to the latest

* chore: Update all deprecations in tracer.ts

Jaeger accepts OTLP now, so the OtlpTraceExporter just works

* update package-lock for (hopefully) desired package.json dep updates

* sync package-lock.json

* sync package-lock.json again (dropping dev:true from '@types/express', why I am not sure)

* add setup script and alternative install

* sync package-lock.json

* bump the express example's dep to the instr-express version in the repo

I also had to manually remove this (vestigial?) entry in package-lock.json
that was breaking 'npm install'.

* signing off on changes

Signed-off-by: Jamie Danielson <jamiedanielson@honeycomb.io>

---------

Signed-off-by: Jamie Danielson <jamiedanielson@honeycomb.io>
Co-authored-by: Trent Mick <trentm@gmail.com>
Co-authored-by: Jamie Danielson <jamieedanielson@gmail.com>
Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
Co-authored-by: Jamie Danielson <jamiedanielson@honeycomb.io>
  • Loading branch information
5 people committed Jan 17, 2024
1 parent c8bebc7 commit 3156c94
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 191 deletions.
186 changes: 19 additions & 167 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ shows key aspects of tracing such as
## Installation

```sh
# from this directory
npm install
# from this directory, install all necessary dependencies from the workspace
npm run setup

# OR alternatively, install dependencies from npm as a standalone example app
npm install --workspaces=false
```

Setup [Zipkin Tracing](https://zipkin.io/pages/quickstart.html)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"name": "express-example",
"private": true,
"version": "0.28.0",
"version": "0.34.1",
"description": "Example of Express integration with OpenTelemetry",
"main": "index.js",
"scripts": {
"zipkin:server": "cross-env EXPORTER=zipkin ts-node src/server.ts",
"zipkin:client": "cross-env EXPORTER=zipkin ts-node src/client.ts",
"jaeger:server": "cross-env EXPORTER=jaeger ts-node src/server.ts",
"jaeger:client": "cross-env EXPORTER=jaeger ts-node src/client.ts",
"compile": "tsc -p ."
"compile": "tsc -p .",
"setup": "cd ../../../../ && npm ci && cd plugins/node/opentelemetry-instrumentation-express && npm run compile && cd examples && npm run compile"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/open-telemetry/opentelemetry-js.git"
"url": "git+ssh://git@github.com/open-telemetry/opentelemetry-js-contrib.git",
"directory": "plugins/node/opentelemetry-instrumentation-express"
},
"keywords": [
"opentelemetry",
Expand All @@ -26,24 +27,25 @@
"author": "OpenTelemetry Authors",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
"url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express/examples#readme",
"dependencies": {
"@opentelemetry/api": "^1.0.0",
"@opentelemetry/exporter-jaeger": "^1.0.0",
"@opentelemetry/exporter-zipkin": "^1.0.0",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/exporter-jaeger": "^1.18.1",
"@opentelemetry/exporter-trace-otlp-proto": "^0.46.0",
"@opentelemetry/exporter-zipkin": "^1.18.1",
"@opentelemetry/instrumentation": "^0.46.0",
"@opentelemetry/instrumentation-express": "0.28.0",
"@opentelemetry/instrumentation-express": "^0.34.1",
"@opentelemetry/instrumentation-http": "^0.46.0",
"@opentelemetry/resources": "^1.0.0",
"@opentelemetry/sdk-trace-base": "^1.0.0",
"@opentelemetry/sdk-trace-node": "^1.0.0",
"@opentelemetry/semantic-conventions": "^1.0.0",
"@opentelemetry/resources": "^1.18.1",
"@opentelemetry/sdk-trace-base": "^1.18.1",
"@opentelemetry/sdk-trace-node": "^1.18.1",
"@opentelemetry/semantic-conventions": "^1.18.1",
"axios": "^1.6.0",
"cross-env": "^7.0.3",
"express": "^4.17.1"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme",
"devDependencies": {
"@types/express": "^4.17.13",
"ts-node": "^10.6.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
'use strict';

import { Sampler, SpanKind } from "@opentelemetry/api";
import { SpanKind, Attributes } from "@opentelemetry/api";

const opentelemetry = require('@opentelemetry/api');

// Not functionally required but gives some insight what happens behind the scenes
const { diag, DiagConsoleLogger, DiagLogLevel } = opentelemetry;
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);

import { AlwaysOnSampler } from '@opentelemetry/core';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
import { Sampler, AlwaysOnSampler, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
import { Resource } from '@opentelemetry/resources';
import { SemanticAttributes, SemanticResourceAttributes as ResourceAttributesSC } from '@opentelemetry/semantic-conventions';
import { SpanAttributes } from "@opentelemetry/api/build/src/trace/attributes";

const Exporter = (process.env.EXPORTER || '').toLowerCase().startsWith('z') ? ZipkinExporter : JaegerExporter;
const Exporter = (process.env.EXPORTER || '').toLowerCase().startsWith('z') ? ZipkinExporter : OTLPTraceExporter;
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');

Expand Down Expand Up @@ -50,7 +48,7 @@ export const setupTracing = (serviceName: string) => {
return opentelemetry.trace.getTracer(serviceName);
};

type FilterFunction = (spanName: string, spanKind: SpanKind, attributes: SpanAttributes) => boolean;
type FilterFunction = (spanName: string, spanKind: SpanKind, attributes: Attributes) => boolean;

function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
return {
Expand All @@ -66,6 +64,6 @@ function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
}
}

function ignoreHealthCheck(spanName: string, spanKind: SpanKind, attributes: SpanAttributes) {
function ignoreHealthCheck(spanName: string, spanKind: SpanKind, attributes: Attributes) {
return spanKind !== opentelemetry.SpanKind.SERVER || attributes[SemanticAttributes.HTTP_ROUTE] !== "/health";
}

0 comments on commit 3156c94

Please sign in to comment.