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

feat: adding proto over http for collector exporter #1302

Merged
merged 13 commits into from
Jul 22, 2020
1 change: 1 addition & 0 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"exclude": [
"**/*.d.ts",
"build/**/*.*",
"generated/**/*.*",
"src/index.ts",
"src/platform/**/index.ts",
"src/platform/browser/*.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
receivers:
otlp: {}
otlp:
{}
# keep it when upgrading to version 0.5+
# protocols:
# grpc:
# http:
# endpoint: localhost:55680

exporters:
zipkin:
Expand Down
6 changes: 0 additions & 6 deletions examples/collector-exporter-node/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ services:
# Collector
collector:
image: otel/opentelemetry-collector:0.4.0
networks:
- otelcol
command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"]
volumes:
- ./collector-config.yaml:/conf/collector-config.yaml
Expand All @@ -15,10 +13,6 @@ services:
# Zipkin
zipkin-all-in-one:
image: openzipkin/zipkin:latest
networks:
- otelcol
ports:
- "9411:9411"

networks:
otelcol:
3 changes: 2 additions & 1 deletion examples/collector-exporter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"main": "index.js",
"scripts": {
"start": "node ./start.js",
"docker:start": "cd ./docker && docker-compose down && docker-compose up -d",
"docker:start": "cd ./docker && docker-compose down && docker-compose up",
"docker:startd": "cd ./docker && docker-compose down && docker-compose up -d",
"docker:stop": "cd ./docker && docker-compose down"
},
"repository": {
Expand Down
3 changes: 2 additions & 1 deletion examples/collector-exporter-node/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const exporter = new CollectorTraceExporter({
// headers: {
// foo: 'bar'
// },
protocolNode: CollectorProtocolNode.HTTP_JSON,
protocolNode: CollectorProtocolNode.HTTP_PROTO,
// protocolNode: CollectorProtocolNode.HTTP_JSON,
});

const provider = new BasicTracerProvider();
Expand Down
27 changes: 25 additions & 2 deletions packages/opentelemetry-exporter-collector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,33 @@ provider.register();

```

## Usage in Node - PROTO over http

```js
const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { CollectorExporter, CollectorTransportNode } = require('@opentelemetry/exporter-collector');

const collectorOptions = {
protocolNode: CollectorTransportNode.HTTP_PROTO,
serviceName: 'basic-service',
url: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:55680/v1/trace
headers: {
foo: 'bar'
}, //an optional object containing custom headers to be sent with each request will only work with json over http
};

const provider = new BasicTracerProvider();
const exporter = new CollectorExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

provider.register();

```

## Running opentelemetry-collector locally to see the traces

1. Go to examples/basic-tracer-node
2. run `npm run collector:docker:ot`
1. Go to examples/collector-exporter-node
2. run `npm run docker:start`
3. Open page at `http://localhost:9411/zipkin/` to observe the traces

## Useful links
Expand Down
13 changes: 13 additions & 0 deletions packages/opentelemetry-exporter-collector/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
clear
git submodule sync --recursive
git submodule update --init --recursive

OUT_DIR="./generated"

protoc \
--js_out="import_style=commonjs,binary:${OUT_DIR}" \
--proto_path="src/platform/node/protos/" \
opentelemetry/proto/common/v1/common.proto \
opentelemetry/proto/resource/v1/resource.proto \
opentelemetry/proto/trace/v1/trace.proto \
opentelemetry/proto/collector/trace/v1/trace_service.proto \
Loading