diff --git a/packages/opentelemetry-exporter-collector/package.json b/packages/opentelemetry-exporter-collector/package.json index 40f4cfd659f..9e11325b521 100644 --- a/packages/opentelemetry-exporter-collector/package.json +++ b/packages/opentelemetry-exporter-collector/package.json @@ -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", @@ -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" } } diff --git a/packages/opentelemetry-exporter-collector/src/CollectorExporter.ts b/packages/opentelemetry-exporter-collector/src/CollectorExporter.ts index 82aee233998..4e2c71504f5 100644 --- a/packages/opentelemetry-exporter-collector/src/CollectorExporter.ts +++ b/packages/opentelemetry-exporter-collector/src/CollectorExporter.ts @@ -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 @@ -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); } diff --git a/packages/opentelemetry-exporter-collector/src/platform/browser/sendSpans.ts b/packages/opentelemetry-exporter-collector/src/platform/browser/sendSpans.ts index ca8b1f9203d..e3836266cf2 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/browser/sendSpans.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/browser/sendSpans.ts @@ -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 @@ -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: { @@ -66,7 +69,7 @@ export function sendSpans( }, attributes: collectorExporter.attributes, }, - // resource: '', not implemented + resource: resource.labels, spans, }; diff --git a/packages/opentelemetry-exporter-collector/src/platform/node/sendSpans.ts b/packages/opentelemetry-exporter-collector/src/platform/node/sendSpans.ts index aaf23d2820a..363bcc5ce6c 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/node/sendSpans.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/node/sendSpans.ts @@ -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 @@ -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: { @@ -70,7 +73,7 @@ export function sendSpans( }, attributes: collectorExporter.attributes, }, - // resource: '', not implemented + resource: resource.labels, spans, }; const body = JSON.stringify(exportTraceServiceRequest);