-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adding example for collector-exporter for node with opent… (#958)
* chore: adding example for collector-exporter for node with opentelemetry-collector * chore: fixing readme * chore: fixing readme * chore: using fixed version of global gts for circle ci * chore: cleaning up docker config * chore: aligning global packages version to those used in project * chore: adding example for collector-exporter for node with opentelemetry-collector * chore: testing circle ci * chore: trying to fix circleci * chore: trying to fix circleci * chore: trying to fix circleci * chore: trying to fix circleci * chore: trying to fix circleci * chore: trying to fix circleci * chore: trying to fix circleci * chore: updating circle ci gtc command name * chore: reviews * chore: lint
- Loading branch information
Showing
7 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Overview | ||
|
||
This example shows how to use [@opentelemetry/exporter-collector](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-collector) to instrument a simple Node.js application. | ||
|
||
This example will export spans data simultaneously using [Exporter Collector](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-collector) and grpc. It will use [proto format](https://github.com/open-telemetry/opentelemetry-proto). | ||
|
||
|
||
## Installation | ||
|
||
```shell script | ||
$ # from this directory | ||
$ npm install | ||
``` | ||
|
||
## Run the Application | ||
|
||
1. Run docker | ||
```shell script | ||
$ # from this directory | ||
$ npm run docker:start | ||
``` | ||
|
||
2. Run app | ||
```shell script | ||
$ # from this directory | ||
$ npm start | ||
``` | ||
|
||
3. Open page at http://localhost:9411/zipkin/ - you should be able to see the spans in zipkin | ||
![Screenshot of the running example](images/spans.png) | ||
|
||
|
||
## Useful links | ||
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/> | ||
- For more information on tracing, visit: <https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing> | ||
|
||
## LICENSE | ||
|
||
Apache License 2.0 |
18 changes: 18 additions & 0 deletions
18
examples/collector-exporter-node/docker/collector-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
receivers: | ||
otlp: | ||
endpoint: 0.0.0.0:55678 | ||
|
||
exporters: | ||
zipkin: | ||
url: "http://zipkin-all-in-one:9411/api/v2/spans" | ||
|
||
processors: | ||
batch: | ||
queued_retry: | ||
|
||
service: | ||
pipelines: | ||
traces: | ||
receivers: [otlp] | ||
exporters: [zipkin] | ||
processors: [batch, queued_retry] |
19 changes: 19 additions & 0 deletions
19
examples/collector-exporter-node/docker/docker-compose.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: "2" | ||
services: | ||
|
||
# Collector | ||
collector: | ||
image: omnition/opentelemetry-collector-contrib:0.2.8 | ||
command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"] | ||
volumes: | ||
- ./collector-config.yaml:/conf/collector-config.yaml | ||
ports: | ||
- "55678:55678" | ||
depends_on: | ||
- zipkin-all-in-one | ||
|
||
# Zipkin | ||
zipkin-all-in-one: | ||
image: openzipkin/zipkin:latest | ||
ports: | ||
- "9411:9411" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "example-collector-exporter-node", | ||
"private": true, | ||
"version": "0.6.1", | ||
"description": "Example of using @opentelemetry/collector-exporter in Node.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node ./start.js", | ||
"docker:start": "cd ./docker && docker-compose down && docker-compose up", | ||
"docker:stop": "cd ./docker && docker-compose down" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/open-telemetry/opentelemetry-js.git" | ||
}, | ||
"keywords": [ | ||
"opentelemetry", | ||
"tracing" | ||
], | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"author": "OpenTelemetry Authors", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/open-telemetry/opentelemetry-js/issues" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/api": "^0.6.1", | ||
"@opentelemetry/exporter-collector": "^0.6.1", | ||
"@opentelemetry/tracing": "^0.6.1" | ||
}, | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
const opentelemetry = require('@opentelemetry/api'); | ||
const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/tracing'); | ||
const { CollectorExporter } = require('@opentelemetry/exporter-collector'); | ||
|
||
const address = '127.0.0.1:55678'; | ||
const exporter = new CollectorExporter({ | ||
serviceName: 'basic-service', | ||
url: address, | ||
}); | ||
|
||
const provider = new BasicTracerProvider(); | ||
provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); | ||
provider.register(); | ||
|
||
const tracer = opentelemetry.trace.getTracer('example-collector-exporter-node'); | ||
|
||
// Create a span. A span must be closed. | ||
const parentSpan = tracer.startSpan('main'); | ||
for (let i = 0; i < 10; i += 1) { | ||
doWork(parentSpan); | ||
} | ||
// Be sure to end the span. | ||
parentSpan.end(); | ||
|
||
// give some time before it is closed | ||
setTimeout(() => { | ||
// flush and close the connection. | ||
exporter.shutdown(); | ||
}, 2000); | ||
|
||
function doWork(parent) { | ||
// Start another span. In this example, the main method already started a | ||
// span, so that'll be the parent span, and this will be a child span. | ||
const span = tracer.startSpan('doWork', { | ||
parent, | ||
}); | ||
|
||
// simulate some random work. | ||
for (let i = 0; i <= Math.floor(Math.random() * 40000000); i += 1) { | ||
// empty | ||
} | ||
// Set attributes to the span. | ||
span.setAttribute('key', 'value'); | ||
|
||
// Annotate our span to capture metadata about our operation | ||
span.addEvent('invoking doWork'); | ||
|
||
// end span | ||
span.end(); | ||
} |