@opentelemetry/exporter-collector
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -22,2 +22,3 @@ "use strict"; | ||
const index_1 = require("./platform/index"); | ||
const resources_1 = require("@opentelemetry/resources"); | ||
const DEFAULT_SERVICE_NAME = 'collector-exporter'; | ||
@@ -73,5 +74,6 @@ const DEFAULT_COLLECTOR_URL = 'http://localhost:55678/v1/trace'; | ||
this.logger.debug('spans to be sent', spansToBeSent); | ||
const resource = transform_1.toCollectorResource(spansToBeSent.length > 0 ? spans[0].resource : resources_1.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 | ||
index_1.sendSpans(spansToBeSent, resolve, reject, this); | ||
index_1.sendSpans(spansToBeSent, resolve, reject, this, resource); | ||
} | ||
@@ -95,8 +97,2 @@ catch (e) { | ||
index_1.onShutdown(this.shutdown); | ||
// @TODO get spans from span processor (batch) | ||
this._exportSpans([]) | ||
.then(() => { | ||
this.logger.debug('shutdown completed'); | ||
}) | ||
.catch(() => { }); | ||
} | ||
@@ -103,0 +99,0 @@ } |
@@ -35,3 +35,4 @@ /*! | ||
* @param collectorExporter | ||
* @param resource | ||
*/ | ||
export declare function sendSpans(spans: collectorTypes.Span[], onSuccess: () => void, onError: (status?: number) => void, collectorExporter: CollectorExporter): void; | ||
export declare function sendSpans(spans: collectorTypes.Span[], onSuccess: () => void, onError: (status?: number) => void, collectorExporter: CollectorExporter, resource: collectorTypes.Resource): void; |
@@ -44,4 +44,5 @@ "use strict"; | ||
* @param collectorExporter | ||
* @param resource | ||
*/ | ||
function sendSpans(spans, onSuccess, onError, collectorExporter) { | ||
function sendSpans(spans, onSuccess, onError, collectorExporter, resource) { | ||
const exportTraceServiceRequest = { | ||
@@ -63,3 +64,3 @@ node: { | ||
}, | ||
// resource: '', not implemented | ||
resource, | ||
spans, | ||
@@ -66,0 +67,0 @@ }; |
@@ -37,3 +37,5 @@ /*! | ||
* @param collectorExporter | ||
* @param resource | ||
*/ | ||
export declare function sendSpans(spans: collectorTypes.Span[], onSuccess: () => void, onError: (status?: number) => void, collectorExporter: CollectorExporter): void; | ||
export declare function sendSpans(spans: collectorTypes.Span[], onSuccess: () => void, onError: (status?: number) => void, collectorExporter: CollectorExporter, resource: collectorTypes.Resource): void; | ||
export declare function toCollectorTraceServiceRequest(spans: collectorTypes.Span[], collectorExporter: CollectorExporter, resource: collectorTypes.Resource): collectorTypes.ExportTraceServiceRequest; |
@@ -45,23 +45,6 @@ "use strict"; | ||
* @param collectorExporter | ||
* @param resource | ||
*/ | ||
function sendSpans(spans, onSuccess, onError, collectorExporter) { | ||
const exportTraceServiceRequest = { | ||
node: { | ||
identifier: { | ||
hostName: collectorExporter.hostName, | ||
startTimestamp: core.hrTimeToTimeStamp(core.hrTime()), | ||
}, | ||
libraryInfo: { | ||
language: 6 /* NODE_JS */, | ||
coreLibraryVersion: core.VERSION, | ||
exporterVersion: version_1.VERSION, | ||
}, | ||
serviceInfo: { | ||
name: collectorExporter.serviceName, | ||
}, | ||
attributes: collectorExporter.attributes, | ||
}, | ||
// resource: '', not implemented | ||
spans, | ||
}; | ||
function sendSpans(spans, onSuccess, onError, collectorExporter, resource) { | ||
const exportTraceServiceRequest = toCollectorTraceServiceRequest(spans, collectorExporter, resource); | ||
const body = JSON.stringify(exportTraceServiceRequest); | ||
@@ -98,2 +81,24 @@ const parsedUrl = url.parse(collectorExporter.url); | ||
exports.sendSpans = sendSpans; | ||
function toCollectorTraceServiceRequest(spans, collectorExporter, resource) { | ||
return { | ||
node: { | ||
identifier: { | ||
hostName: collectorExporter.hostName, | ||
startTimestamp: core.hrTimeToTimeStamp(core.hrTime()), | ||
}, | ||
libraryInfo: { | ||
language: 6 /* NODE_JS */, | ||
coreLibraryVersion: core.VERSION, | ||
exporterVersion: version_1.VERSION, | ||
}, | ||
serviceInfo: { | ||
name: collectorExporter.serviceName, | ||
}, | ||
attributes: collectorExporter.attributes, | ||
}, | ||
resource, | ||
spans, | ||
}; | ||
} | ||
exports.toCollectorTraceServiceRequest = toCollectorTraceServiceRequest; | ||
//# sourceMappingURL=sendSpans.js.map |
@@ -19,2 +19,3 @@ /*! | ||
import * as collectorTypes from './types'; | ||
import { Resource } from '@opentelemetry/resources'; | ||
/** | ||
@@ -57,1 +58,6 @@ * convert string to maximum length of 128, providing information of truncated bytes | ||
export declare function toCollectorSpan(span: ReadableSpan): collectorTypes.Span; | ||
/** | ||
* converts span resource | ||
* @param resource | ||
*/ | ||
export declare function toCollectorResource(resource: Resource): collectorTypes.Resource; |
@@ -112,4 +112,4 @@ "use strict"; | ||
function toCollectorLinkType(span, link) { | ||
const linkSpanId = link.spanContext.spanId; | ||
const linkTraceId = link.spanContext.traceId; | ||
const linkSpanId = link.context.spanId; | ||
const linkTraceId = link.context.traceId; | ||
const spanParentId = span.parentSpanId; | ||
@@ -130,4 +130,4 @@ const spanTraceId = span.spanContext.traceId; | ||
const collectorLink = { | ||
traceId: core_1.hexToBase64(link.spanContext.traceId), | ||
spanId: core_1.hexToBase64(link.spanContext.spanId), | ||
traceId: core_1.hexToBase64(link.context.traceId), | ||
spanId: core_1.hexToBase64(link.context.spanId), | ||
type: toCollectorLinkType(span, link), | ||
@@ -171,2 +171,13 @@ }; | ||
/** | ||
* converts span resource | ||
* @param resource | ||
*/ | ||
function toCollectorResource(resource) { | ||
const labels = {}; | ||
Object.keys(resource.labels).forEach(name => (labels[name] = String(resource.labels[name]))); | ||
// @TODO: add type support | ||
return { labels }; | ||
} | ||
exports.toCollectorResource = toCollectorResource; | ||
/** | ||
* @param traceState | ||
@@ -173,0 +184,0 @@ */ |
@@ -16,2 +16,2 @@ /*! | ||
*/ | ||
export declare const VERSION = "0.4.0"; | ||
export declare const VERSION = "0.5.0"; |
@@ -19,3 +19,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.4.0'; | ||
exports.VERSION = '0.5.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/exporter-collector", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "OpenTelemetry Collector Exporter allows user to send collected traces to the OpenTelemetry Collector", | ||
@@ -13,3 +13,4 @@ "main": "build/src/index.js", | ||
"scripts": { | ||
"check": "gts check", | ||
"lint": "gts check", | ||
"lint:fix": "gts fix", | ||
"clean": "rimraf build/*", | ||
@@ -19,7 +20,6 @@ "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", | ||
"compile": "npm run version:update && tsc -p .", | ||
"fix": "gts fix", | ||
"prepare": "npm run compile", | ||
"tdd": "npm run test -- --watch-extensions ts --watch", | ||
"tdd:browser": "karma start", | ||
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.ts' --exclude 'test/browser/**/*.ts'", | ||
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", | ||
"test:browser": "nyc karma start --single-run", | ||
@@ -84,7 +84,8 @@ "version:update": "node ../../scripts/version-update.js", | ||
"dependencies": { | ||
"@opentelemetry/api": "^0.4.0", | ||
"@opentelemetry/base": "^0.4.0", | ||
"@opentelemetry/core": "^0.4.0", | ||
"@opentelemetry/tracing": "^0.4.0" | ||
"@opentelemetry/api": "^0.5.0", | ||
"@opentelemetry/base": "^0.5.0", | ||
"@opentelemetry/core": "^0.5.0", | ||
"@opentelemetry/resources": "^0.5.0", | ||
"@opentelemetry/tracing": "^0.5.0" | ||
} | ||
} |
@@ -18,3 +18,2 @@ # OpenTelemetry Collector Exporter for web and node | ||
```js | ||
import * as opentelemetry from '@opentelemetry/api'; | ||
import { SimpleSpanProcessor } from '@opentelemetry/tracing'; | ||
@@ -32,3 +31,3 @@ import { WebTracerProvider } from '@opentelemetry/web'; | ||
opentelemetry.trace.initGlobalTracerProvider(provider); | ||
provider.register(); | ||
@@ -39,3 +38,2 @@ ``` | ||
```js | ||
const opentelemetry = require('@opentelemetry/api'); | ||
const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/tracing'); | ||
@@ -52,3 +50,3 @@ const { CollectorExporter } = require('@opentelemetry/exporter-collector'); | ||
opentelemetry.trace.initGlobalTracerProvider(provider); | ||
provider.register(); | ||
@@ -55,0 +53,0 @@ ``` |
66980
1382
5
76
+ Added@opentelemetry/api@0.5.2(transitive)
+ Added@opentelemetry/base@0.5.2(transitive)
+ Added@opentelemetry/context-base@0.5.2(transitive)
+ Added@opentelemetry/core@0.5.2(transitive)
+ Added@opentelemetry/resources@0.5.2(transitive)
+ Added@opentelemetry/tracing@0.5.2(transitive)
+ Addedsemver@7.6.3(transitive)
- Removed@opentelemetry/api@0.4.0(transitive)
- Removed@opentelemetry/base@0.4.0(transitive)
- Removed@opentelemetry/core@0.4.0(transitive)
- Removed@opentelemetry/scope-base@0.4.0(transitive)
- Removed@opentelemetry/tracing@0.4.0(transitive)
- Removedsemver@6.3.1(transitive)
Updated@opentelemetry/api@^0.5.0
Updated@opentelemetry/base@^0.5.0
Updated@opentelemetry/core@^0.5.0