@uptrace/core
Advanced tools
Comparing version 0.4.3 to 0.18.0
@@ -1,16 +0,12 @@ | ||
import { TracerProvider, Span, SpanAttributes } from '@opentelemetry/api'; | ||
import { Config, EnrichedConfig } from './config'; | ||
import { Span, SpanAttributes } from '@opentelemetry/api'; | ||
import { DSN } from './config'; | ||
export declare class Client { | ||
private _cfg; | ||
private _bsp; | ||
private _provider; | ||
private _dsn; | ||
private _tracer?; | ||
constructor(cfg: EnrichedConfig); | ||
close(): Promise<void>; | ||
getTracerProvider(): TracerProvider; | ||
constructor(dsn: DSN); | ||
reportException(err: Error | string, attrs?: SpanAttributes): void; | ||
traceUrl(span: Span): string; | ||
traceUrl(span?: Span): string; | ||
private _internalTracer; | ||
} | ||
export declare function createClient(_cfg: Config): Client; | ||
export declare function createClient(dsn: DSN): Client; | ||
//# sourceMappingURL=client.d.ts.map |
@@ -5,34 +5,10 @@ "use strict"; | ||
var api_1 = require("@opentelemetry/api"); | ||
var tracing_1 = require("@opentelemetry/tracing"); | ||
var config_1 = require("./config"); | ||
var exporter_1 = require("./exporter"); | ||
var DUMMY_SPAN_NAME = '__dummy__'; | ||
var Client = /** @class */ (function () { | ||
function Client(cfg) { | ||
this._cfg = cfg; | ||
this._provider = this._cfg.provider; | ||
var exporter = new exporter_1.SpanExporter(cfg); | ||
this._bsp = new tracing_1.BatchSpanProcessor(exporter, { | ||
maxExportBatchSize: 1000, | ||
maxQueueSize: 1000, | ||
scheduledDelayMillis: 5 * 1000, | ||
}); | ||
this._provider.addSpanProcessor(this._bsp); | ||
this._provider.register({ | ||
propagator: cfg.propagator, | ||
contextManager: cfg.contextManager, | ||
}); | ||
function Client(dsn) { | ||
this._dsn = dsn; | ||
} | ||
Client.prototype.close = function () { | ||
return this._bsp.shutdown(); | ||
}; | ||
Client.prototype.getTracerProvider = function () { | ||
return this._provider; | ||
}; | ||
// reportException reports an exception as a span event creating a dummy span if necessary. | ||
Client.prototype.reportException = function (err, attrs) { | ||
if (attrs === void 0) { attrs = {}; } | ||
if (this._cfg.disabled) { | ||
return; | ||
} | ||
var startedSpan = false; | ||
@@ -59,6 +35,9 @@ var tracer = this._internalTracer(); | ||
Client.prototype.traceUrl = function (span) { | ||
var v = this._cfg._dsn; | ||
var host = v.host.slice(4); | ||
var traceId = span.context().traceId; | ||
return v.scheme + "//" + host + "/search/" + v.projectId + "?q=" + traceId; | ||
if (!span) { | ||
span = api_1.getSpan(api_1.context.active()); | ||
} | ||
var dsn = this._dsn; | ||
var host = dsn.host.slice(4); | ||
var traceId = span === null || span === void 0 ? void 0 : span.context().traceId; | ||
return dsn.scheme + "//" + host + "/search/" + dsn.projectId + "?q=" + traceId; | ||
}; | ||
@@ -74,7 +53,6 @@ Client.prototype._internalTracer = function () { | ||
exports.Client = Client; | ||
function createClient(_cfg) { | ||
var cfg = config_1.createConfig(_cfg); | ||
return new Client(cfg); | ||
function createClient(dsn) { | ||
return new Client(dsn); | ||
} | ||
exports.createClient = createClient; | ||
//# sourceMappingURL=client.js.map |
@@ -1,25 +0,12 @@ | ||
import { Sampler, TextMapPropagator, ContextManager } from '@opentelemetry/api'; | ||
import { BasicTracerProvider } from '@opentelemetry/tracing'; | ||
import { Resource } from '@opentelemetry/resources'; | ||
import { SpanFilter } from './types'; | ||
import type { SpanData } from './types'; | ||
export interface Config { | ||
dsn?: string; | ||
dsn: string; | ||
serviceName?: string; | ||
serviceVersion?: string; | ||
resourceAttributes?: Record<string, any>; | ||
resource?: Resource; | ||
sampler?: Sampler; | ||
propagator?: TextMapPropagator | null; | ||
contextManager?: ContextManager | null; | ||
filter?: SpanFilter; | ||
disabled?: boolean; | ||
filters?: SpanFilter[]; | ||
provider: BasicTracerProvider; | ||
onBeforeSend?: (span: SpanData) => void; | ||
} | ||
export declare function createConfig(_cfg: Config): EnrichedConfig; | ||
export interface EnrichedConfig extends Config { | ||
_dsn: DSN; | ||
} | ||
export declare function createResource(cfg: Partial<Config>): Resource; | ||
interface DSN { | ||
export declare function createResource(resource: Resource | undefined, resourceAttributes: Record<string, any> | undefined, serviceName: string, serviceVersion: string): Resource; | ||
export interface DSN { | ||
scheme: string; | ||
@@ -30,3 +17,3 @@ host: string; | ||
} | ||
export {}; | ||
export declare function parseDSN(s: string): DSN; | ||
//# sourceMappingURL=config.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createResource = exports.createConfig = void 0; | ||
exports.parseDSN = exports.createResource = void 0; | ||
var resources_1 = require("@opentelemetry/resources"); | ||
function createConfig(_cfg) { | ||
var _a, _b; | ||
var cfg = _cfg; | ||
try { | ||
cfg._dsn = parseDSN((_a = _cfg.dsn) !== null && _a !== void 0 ? _a : ''); | ||
} | ||
catch (err) { | ||
cfg.disabled = true; | ||
console.error('Uptrace is disabled:', (_b = err.message) !== null && _b !== void 0 ? _b : err); | ||
cfg._dsn = parseDSN('https://<token>@api.uptrace.dev/<project_id>'); | ||
} | ||
if (!cfg.filters) { | ||
cfg.filters = []; | ||
} | ||
if (cfg.filter) { | ||
cfg.filters.push(cfg.filter); | ||
} | ||
return cfg; | ||
} | ||
exports.createConfig = createConfig; | ||
function createResource(cfg) { | ||
var _a, _b; | ||
return _createResource(cfg.resource, cfg.resourceAttributes, (_a = cfg.serviceName) !== null && _a !== void 0 ? _a : '', (_b = cfg.serviceVersion) !== null && _b !== void 0 ? _b : ''); | ||
} | ||
exports.createResource = createResource; | ||
function _createResource(resource, resourceAttributes, serviceName, serviceVersion) { | ||
function createResource(resource, resourceAttributes, serviceName, serviceVersion) { | ||
var attrs = {}; | ||
@@ -49,5 +24,6 @@ if (resourceAttributes) { | ||
} | ||
exports.createResource = createResource; | ||
function parseDSN(s) { | ||
if (!s) { | ||
throw new Error('uptrace: either dsn option or UPTRACE_DSN is required'); | ||
throw new Error('either dsn option or UPTRACE_DSN is required'); | ||
} | ||
@@ -59,3 +35,3 @@ var u; | ||
catch (err) { | ||
throw new Error("uptrace: can't parse DSN: " + JSON.stringify(s)); | ||
throw new Error("can't parse DSN: " + JSON.stringify(s)); | ||
} | ||
@@ -69,2 +45,3 @@ return { | ||
} | ||
exports.parseDSN = parseDSN; | ||
//# sourceMappingURL=config.js.map |
import { ExportResult } from '@opentelemetry/core'; | ||
import { SpanExporter as ISpanExporter, ReadableSpan } from '@opentelemetry/tracing'; | ||
import { EnrichedConfig } from './config'; | ||
import { DSN } from './config'; | ||
export declare class SpanExporter implements ISpanExporter { | ||
private _cfg; | ||
private _endpoint; | ||
private _headers; | ||
constructor(cfg: EnrichedConfig); | ||
private _filter; | ||
constructor(dsn: DSN); | ||
export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void; | ||
@@ -11,0 +9,0 @@ shutdown(): Promise<void>; |
@@ -8,42 +8,18 @@ "use strict"; | ||
var SpanExporter = /** @class */ (function () { | ||
function SpanExporter(cfg) { | ||
function SpanExporter(dsn) { | ||
this._endpoint = ''; | ||
this._headers = {}; | ||
this._cfg = cfg; | ||
if (this._cfg.disabled) { | ||
return; | ||
} | ||
var v = this._cfg._dsn; | ||
this._endpoint = v.scheme + "//" + v.host + "/api/v1/tracing/" + v.projectId + "/spans"; | ||
this._endpoint = dsn.scheme + "//" + dsn.host + "/api/v1/tracing/" + dsn.projectId + "/spans"; | ||
this._headers = { | ||
Authorization: 'Bearer ' + this._cfg._dsn.token, | ||
Authorization: 'Bearer ' + dsn.token, | ||
'Content-Type': 'application/json', | ||
}; | ||
} | ||
SpanExporter.prototype._filter = function (span) { | ||
if (!this._cfg.filters) { | ||
return true; | ||
} | ||
for (var _i = 0, _a = this._cfg.filters; _i < _a.length; _i++) { | ||
var fn = _a[_i]; | ||
if (!fn(span)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
SpanExporter.prototype.export = function (spans, resultCallback) { | ||
if (this._cfg.disabled) { | ||
resultCallback({ code: core_1.ExportResultCode.SUCCESS }); | ||
return; | ||
} | ||
var uptraceSpans = []; | ||
var outSpans = []; | ||
for (var _i = 0, spans_1 = spans; _i < spans_1.length; _i++) { | ||
var span = spans_1[_i]; | ||
var out = uptraceSpan(span); | ||
if (this._filter(out)) { | ||
uptraceSpans.push(out); | ||
} | ||
outSpans.push(_span(span)); | ||
} | ||
var body = JSON.stringify({ spans: uptraceSpans }); | ||
var body = JSON.stringify({ spans: outSpans }); | ||
cross_fetch_1.default(this._endpoint, { | ||
@@ -76,3 +52,3 @@ method: 'POST', | ||
exports.SpanExporter = SpanExporter; | ||
function uptraceSpan(span) { | ||
function _span(span) { | ||
var out = { | ||
@@ -82,3 +58,3 @@ id: span.spanContext.spanId, | ||
name: span.name, | ||
kind: uptraceKind(span.kind), | ||
kind: _kind(span.kind), | ||
startTime: core_1.hrTimeToTimeStamp(span.startTime), | ||
@@ -88,3 +64,3 @@ endTime: core_1.hrTimeToTimeStamp(span.endTime), | ||
attrs: span.attributes, | ||
statusCode: uptraceStatus(span.status.code), | ||
statusCode: _status(span.status.code), | ||
tracerName: span.instrumentationLibrary.name, | ||
@@ -102,10 +78,10 @@ }; | ||
if (span.events.length) { | ||
out.events = uptraceEvents(span.events); | ||
out.events = _events(span.events); | ||
} | ||
if (span.links.length) { | ||
out.links = uptraceLinks(span.links); | ||
out.links = _links(span.links); | ||
} | ||
return out; | ||
} | ||
function uptraceEvents(events) { | ||
function _events(events) { | ||
var uptraceEvents = []; | ||
@@ -122,3 +98,3 @@ for (var _i = 0, events_1 = events; _i < events_1.length; _i++) { | ||
} | ||
function uptraceLinks(links) { | ||
function _links(links) { | ||
var uptraceLinks = []; | ||
@@ -135,3 +111,3 @@ for (var _i = 0, links_1 = links; _i < links_1.length; _i++) { | ||
} | ||
function uptraceKind(kind) { | ||
function _kind(kind) { | ||
switch (kind) { | ||
@@ -150,3 +126,3 @@ case api_1.SpanKind.SERVER: | ||
} | ||
function uptraceStatus(code) { | ||
function _status(code) { | ||
switch (code) { | ||
@@ -153,0 +129,0 @@ case api_1.SpanStatusCode.OK: |
@@ -1,5 +0,6 @@ | ||
export { Config, createResource } from './config'; | ||
export { Client, createClient } from './client'; | ||
export { SpanExporter } from './exporter'; | ||
export * from './config'; | ||
export * from './client'; | ||
export * from './exporter'; | ||
export * from './types'; | ||
export * from './version'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -13,11 +13,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SpanExporter = exports.createClient = exports.Client = exports.createResource = void 0; | ||
var config_1 = require("./config"); | ||
Object.defineProperty(exports, "createResource", { enumerable: true, get: function () { return config_1.createResource; } }); | ||
var client_1 = require("./client"); | ||
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } }); | ||
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } }); | ||
var exporter_1 = require("./exporter"); | ||
Object.defineProperty(exports, "SpanExporter", { enumerable: true, get: function () { return exporter_1.SpanExporter; } }); | ||
__exportStar(require("./config"), exports); | ||
__exportStar(require("./client"), exports); | ||
__exportStar(require("./exporter"), exports); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./version"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.4.3"; | ||
export declare const VERSION = "0.18.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.4.3'; | ||
exports.VERSION = '0.18.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@uptrace/core", | ||
"version": "0.4.3", | ||
"version": "0.18.0", | ||
"description": "Uptrace JS core", | ||
@@ -60,10 +60,10 @@ "main": "build/src/index.js", | ||
"@opentelemetry/tracing": "^0.18.0", | ||
"cross-fetch": "^3.0.6" | ||
"cross-fetch": "^3.1.2" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "8.2.1", | ||
"@types/node": "14.14.33", | ||
"@types/mocha": "8.2.2", | ||
"@types/node": "14.14.35", | ||
"@types/sinon": "9.0.11", | ||
"@typescript-eslint/eslint-plugin": "4.17.0", | ||
"eslint": "7.21.0", | ||
"@typescript-eslint/eslint-plugin": "4.18.0", | ||
"eslint": "7.22.0", | ||
"eslint-plugin-node": "11.1.0", | ||
@@ -70,0 +70,0 @@ "eslint-plugin-prettier": "3.3.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19688
322
Updatedcross-fetch@^3.1.2