Skip to content

Commit

Permalink
update Collector exporter to use Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 committed Mar 6, 2020
1 parent fc81d91 commit 6678784
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-collector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/resources": "^0.4.0",
"@babel/core": "^7.6.0",
"@types/mocha": "^5.2.5",
"@types/node": "^12.6.8",
Expand Down Expand Up @@ -83,6 +82,7 @@
"@opentelemetry/api": "^0.4.0",
"@opentelemetry/base": "^0.4.0",
"@opentelemetry/core": "^0.4.0",
"@opentelemetry/resources": "^0.4.0",
"@opentelemetry/tracing": "^0.4.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Attributes, Logger } from '@opentelemetry/api';
import * as collectorTypes from './types';
import { toCollectorSpan } from './transform';
import { onInit, onShutdown, sendSpans } from './platform/index';
import { Resource } from '@opentelemetry/resources';

/**
* Collector Exporter Config
Expand Down Expand Up @@ -100,10 +101,12 @@ export class CollectorExporter implements SpanExporter {
toCollectorSpan(span)
);
this.logger.debug('spans to be sent', spansToBeSent);
const resource =
spansToBeSent.length > 0 ? spans[0].resource : Resource.empty();

// Send spans to [opentelemetry collector]{@link https://github.com/open-telemetry/opentelemetry-collector}
// it will use the appropriate transport layer automatically depends on platform
sendSpans(spansToBeSent, resolve, reject, this);
sendSpans(spansToBeSent, resolve, reject, this, resource);
} catch (e) {
reject(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Logger } from '@opentelemetry/api';
import { CollectorExporter } from '../../CollectorExporter';
import * as collectorTypes from '../../types';
import { VERSION } from '../../version';
import { Resource } from '@opentelemetry/resources';

/**
* function that is called once when {@link ExporterCollector} is initialised
Expand All @@ -43,12 +44,14 @@ export function onShutdown(shutdownF: EventListener) {
* @param onSuccess
* @param onError
* @param collectorExporter
* @param resource
*/
export function sendSpans(
spans: collectorTypes.Span[],
onSuccess: () => void,
onError: (status?: number) => void,
collectorExporter: CollectorExporter
collectorExporter: CollectorExporter,
resource: Resource
) {
const exportTraceServiceRequest: collectorTypes.ExportTraceServiceRequest = {
node: {
Expand All @@ -66,7 +69,7 @@ export function sendSpans(
},
attributes: collectorExporter.attributes,
},
// resource: '', not implemented
resource: resource.labels,
spans,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as collectorTypes from '../../types';

import * as url from 'url';
import { VERSION } from '../../version';
import { Resource } from '@opentelemetry/resources';

/**
* function that is called once when {@link ExporterCollector} is initialised
Expand All @@ -47,12 +48,14 @@ export function onShutdown(shutdownF: Function) {}
* @param onSuccess
* @param onError
* @param collectorExporter
* @param resource
*/
export function sendSpans(
spans: collectorTypes.Span[],
onSuccess: () => void,
onError: (status?: number) => void,
collectorExporter: CollectorExporter
collectorExporter: CollectorExporter,
resource: Resource
) {
const exportTraceServiceRequest: collectorTypes.ExportTraceServiceRequest = {
node: {
Expand All @@ -70,7 +73,7 @@ export function sendSpans(
},
attributes: collectorExporter.attributes,
},
// resource: '', not implemented
resource: resource.labels,
spans,
};
const body = JSON.stringify(exportTraceServiceRequest);
Expand Down

0 comments on commit 6678784

Please sign in to comment.