Skip to content

Commit

Permalink
Merge branch 'main' into feat/node/perf_hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
d4nyll authored Jan 20, 2024
2 parents 193ea77 + f65f2f1 commit 18299f7
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 195 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://[email protected]/open-telemetry/opentelemetry-js.git"
"url": "git+ssh://[email protected]/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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class ExpressInstrumentation extends InstrumentationBase<
const isError = ![undefined, null, 'route', 'router'].includes(
maybeError
);
if (isError) {
if (!spanHasEnded && isError) {
const [error, message] = asErrorAndMessage(maybeError);
span.recordException(error);
span.setStatus({
Expand Down
Loading

0 comments on commit 18299f7

Please sign in to comment.