Skip to content

Commit

Permalink
updating web examples to latest (open-telemetry#731)
Browse files Browse the repository at this point in the history
Co-authored-by: Naseem <[email protected]>
Co-authored-by: Valentin Marchaud <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2022
1 parent 89f5044 commit b231412
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 27 deletions.
24 changes: 24 additions & 0 deletions examples/web/docker/collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
receivers:
otlp:
protocols:
grpc:
http:
cors_allowed_origins:
- http://*
- https://*

exporters:
zipkin:
endpoint: "http://zipkin-all-in-one:9411/api/v2/spans"
prometheus:
endpoint: "0.0.0.0:9464"

processors:
batch:

service:
pipelines:
traces:
receivers: [otlp]
exporters: [zipkin]
processors: [batch]
21 changes: 21 additions & 0 deletions examples/web/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3"
services:
# Collector
collector:
image: otel/opentelemetry-collector:0.38.0
command: ["--config=/conf/collector-config.yaml"]
volumes:
- ./collector-config.yaml:/conf/collector-config.yaml
ports:
- "9464:9464"
- "4317:4317"
- "4318:4318"
- "55681:55681"
depends_on:
- zipkin-all-in-one

# Zipkin
zipkin-all-in-one:
image: openzipkin/zipkin:latest
ports:
- "9411:9411"
2 changes: 1 addition & 1 deletion examples/web/examples/document-load/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(01 = sampled, 00 = notsampled).
'{version}-{traceId}-{spanId}-{sampleDecision}'
-->
<meta name="traceparent" content="00-ab42124a3c573678d4d8b21ba52df3bf-d21f7bc17caa5aba-01">
<!-- <meta name="traceparent" content="00-ab42124a3c573678d4d8b21ba52df3bf-d21f7bc17caa5aba-01">-->

<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
Expand Down
21 changes: 14 additions & 7 deletions examples/web/examples/document-load/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@ import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-document-load';
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';
import { OTLPTraceExporter } from '@opentelemetry/exporter-otlp-http';
import { B3Propagator } from '@opentelemetry/propagator-b3';
import { CompositePropagator, HttpTraceContextPropagator } from '@opentelemetry/core';
import { CompositePropagator, W3CTraceContextPropagator } from '@opentelemetry/core';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

const provider = new WebTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'web-service-dl',
}),
});

const provider = new WebTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));

provider.register({
contextManager: new ZoneContextManager(),
propagator: new CompositePropagator({
propagators: [
new B3Propagator(),
new HttpTraceContextPropagator(),
new W3CTraceContextPropagator(),
],
}),
});
Expand Down Expand Up @@ -55,8 +62,8 @@ const getData = (url) => new Promise((resolve, reject) => {

// example of keeping track of context between async operations
const prepareClickEvent = () => {
const url1 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/master/package.json';
const url2 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/master/packages/opentelemetry-web/package.json';
const url1 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/main/package.json';
const url2 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/main/packages/opentelemetry-sdk-trace-web/package.json';

const element = document.getElementById('button1');

Expand Down
12 changes: 9 additions & 3 deletions examples/web/examples/meta/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';
import { OTLPTraceExporter } from '@opentelemetry/exporter-otlp-http';
import { B3Propagator } from '@opentelemetry/propagator-b3';
import { getWebAutoInstrumentations } from '@opentelemetry/auto-instrumentations-web';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

const providerWithZone = new WebTracerProvider();
const providerWithZone = new WebTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'web-service-meta',
}),
});

providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter()));
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));

providerWithZone.register({
contextManager: new ZoneContextManager(),
Expand Down
12 changes: 9 additions & 3 deletions examples/web/examples/user-interaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-tra
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { UserInteractionInstrumentation } from '@opentelemetry/instrumentation-user-interaction';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';
import { OTLPTraceExporter } from '@opentelemetry/exporter-otlp-http';
import { B3Propagator } from '@opentelemetry/propagator-b3';
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

const providerWithZone = new WebTracerProvider();
const providerWithZone = new WebTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'web-service-ui',
}),
});

providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter()));
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));

providerWithZone.register({
contextManager: new ZoneContextManager(),
Expand Down
30 changes: 17 additions & 13 deletions examples/web/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "web-examples",
"private": true,
"version": "0.23.0",
"version": "0.26.0",
"description": "Example of using web plugins in browser",
"main": "index.js",
"scripts": {
"docker:start": "cd ./docker && docker-compose down && docker-compose up",
"docker:startd": "cd ./docker && docker-compose down && docker-compose up -d",
"start": "webpack-dev-server -d --progress --colors --port 8090 --config webpack.config.js --hot --inline --host 0.0.0.0 --content-base examples"
},
"repository": {
Expand Down Expand Up @@ -34,18 +36,20 @@
"webpack-merge": "^4.2.2"
},
"dependencies": {
"@opentelemetry/api": "^1.0.2",
"@opentelemetry/auto-instrumentations-web": "^0.24.0",
"@opentelemetry/context-zone": "^0.25.0",
"@opentelemetry/core": "^0.25.0",
"@opentelemetry/exporter-collector": "^0.25.0",
"@opentelemetry/instrumentation": "^0.25.0",
"@opentelemetry/instrumentation-document-load": "^0.23.0",
"@opentelemetry/instrumentation-user-interaction": "^0.23.0",
"@opentelemetry/instrumentation-xml-http-request": "^0.25.0",
"@opentelemetry/propagator-b3": "^0.25.0",
"@opentelemetry/sdk-trace-base": "^0.25.0",
"@opentelemetry/sdk-trace-web": "^0.25.0"
"@opentelemetry/api": "^1.0.3",
"@opentelemetry/auto-instrumentations-web": "~0.26.0",
"@opentelemetry/context-zone": "~1.0.0",
"@opentelemetry/core": "~1.0.0",
"@opentelemetry/exporter-otlp-http": "~0.26.0",
"@opentelemetry/instrumentation": "~0.26.0",
"@opentelemetry/instrumentation-document-load": "~0.26.0",
"@opentelemetry/instrumentation-user-interaction": "~0.26.0",
"@opentelemetry/instrumentation-xml-http-request": "~0.26.0",
"@opentelemetry/propagator-b3": "~1.0.0",
"@opentelemetry/resources": "~1.0.0",
"@opentelemetry/sdk-trace-base": "~1.0.0",
"@opentelemetry/sdk-trace-web": "~1.0.0",
"@opentelemetry/semantic-conventions": "~1.0.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme"
}

0 comments on commit b231412

Please sign in to comment.