Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uptrace/core

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uptrace/core - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

6

build/src/client.d.ts
import { TracerProvider, Span, Attributes } from '@opentelemetry/api';
import { Tracer, TracerConfig } from '@opentelemetry/tracing';
import { Config } from './config';
import { Config, EnrichedConfig } from './config';
export declare class Client {

@@ -9,3 +9,3 @@ private _cfg;

private _tracer?;
constructor(cfg: Config);
constructor(cfg: EnrichedConfig);
close(): Promise<void>;

@@ -18,3 +18,3 @@ getProvider(): TracerProvider;

}
export declare function createClient(cfg?: Partial<Config>): Client;
export declare function createClient(_cfg: Config): Client;
//# sourceMappingURL=client.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createClient = exports.Client = void 0;
var api_1 = require("@opentelemetry/api");
var tracing_1 = require("@opentelemetry/tracing");
var config_1 = require("./config");
var exporter_1 = require("./exporter");

@@ -10,16 +12,6 @@ var DUMMY_SPAN_NAME = '__dummy__';

this._cfg = cfg;
if (this._cfg.provider) {
this._provider = this._cfg.provider;
}
else {
throw new Error('uptrace: config.provider is required');
}
if (!this._cfg.dsn) {
console.error('uptrace: UPTRACE_DSN is empty or missing' +
' (to hide this message, use UPTRACE_DISABLED=True)');
this._cfg.disabled = true;
}
var exporter = new exporter_1.Exporter(cfg);
this._provider = this._cfg.provider;
var exporter = new exporter_1.SpanExporter(cfg);
this._bsp = new tracing_1.BatchSpanProcessor(exporter, {
bufferSize: 10000,
bufferSize: 1000,
bufferTimeout: 5 * 1000,

@@ -49,3 +41,3 @@ });

var tracer = this._internalTracer();
var span = tracer.getCurrentSpan();
var span = api_1.getSpan(api_1.context.active());
if (!span) {

@@ -69,6 +61,6 @@ span = tracer.startSpan(DUMMY_SPAN_NAME);

Client.prototype.traceUrl = function (span) {
var u = this._cfg.dsnURL;
var host = u.host.slice(4);
var v = this._cfg._dsn;
var host = v.host.slice(4);
var traceId = span.context().traceId;
return u.protocol + "//" + host + u.pathname + "/search?q=" + traceId;
return v.scheme + "//" + host + "/" + v.projectId + "/search?q=" + traceId;
};

@@ -84,21 +76,4 @@ Client.prototype._internalTracer = function () {

exports.Client = Client;
function createClient(cfg) {
if (cfg === void 0) { cfg = {}; }
if (cfg.dsn) {
try {
cfg.dsnURL = new URL(cfg.dsn);
}
catch (err) {
throw new Error("uptrace: can't parse dsn: " + err.message);
}
}
if (!cfg.provider) {
throw new Error('uptrace: provider is required');
}
if (!cfg.filters) {
cfg.filters = [];
}
if (cfg.filter) {
cfg.filters.push(cfg.filter);
}
function createClient(_cfg) {
var cfg = config_1.createConfig(_cfg);
return new Client(cfg);

@@ -105,0 +80,0 @@ }

@@ -7,2 +7,5 @@ import { Sampler } from '@opentelemetry/api';

dsn?: string;
serviceName?: string;
serviceVersion?: string;
resourceAttributes?: Record<string, any>;
resource?: Resource;

@@ -12,6 +15,17 @@ sampler?: Sampler;

disabled?: boolean;
dsnURL: URL;
filters: SpanFilter[];
filters?: SpanFilter[];
provider: BasicTracerProvider;
}
export declare function createConfig(_cfg: Config): EnrichedConfig;
export interface EnrichedConfig extends Config {
_dsn: DSN;
}
export declare function createResource(cfg: Partial<Config>): Resource;
interface DSN {
scheme: string;
host: string;
projectId: string;
token: string;
}
export {};
//# sourceMappingURL=config.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createResource = exports.createConfig = 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) {
var attrs = {};
if (resourceAttributes) {
Object.assign(attrs, resourceAttributes);
}
if (serviceName) {
attrs['service.name'] = serviceName;
}
if (serviceVersion) {
attrs['service.version'] = serviceVersion;
}
if (!resource) {
return new resources_1.Resource(attrs);
}
if (!Object.keys(attrs).length) {
return resource;
}
return resource.merge(new resources_1.Resource(attrs));
}
function parseDSN(s) {
if (!s) {
throw new Error('uptrace: either dsn option or UPTRACE_DSN is required');
}
var u;
try {
u = new URL(s);
}
catch (err) {
throw new Error("uptrace: can't parse DSN: " + JSON.stringify(s));
}
return {
scheme: u.protocol,
host: u.host,
projectId: u.pathname.slice(1),
token: u.username,
};
}
//# sourceMappingURL=config.js.map
import { ExportResult } from '@opentelemetry/core';
import { SpanExporter, ReadableSpan } from '@opentelemetry/tracing';
import { Config } from './config';
export declare class Exporter implements SpanExporter {
import { SpanExporter as ISpanExporter, ReadableSpan } from '@opentelemetry/tracing';
import { EnrichedConfig } from './config';
export declare class SpanExporter implements ISpanExporter {
private _cfg;
private _endpoint;
private _headers;
constructor(cfg: Config);
constructor(cfg: EnrichedConfig);
private _filter;

@@ -10,0 +10,0 @@ export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Exporter = void 0;
exports.SpanExporter = void 0;
var cross_fetch_1 = require("cross-fetch");
var core_1 = require("@opentelemetry/core");
var api_1 = require("@opentelemetry/api");
var Exporter = /** @class */ (function () {
function Exporter(cfg) {
var SpanExporter = /** @class */ (function () {
function SpanExporter(cfg) {
this._endpoint = '';

@@ -15,10 +15,10 @@ this._headers = {};

}
var u = this._cfg.dsnURL;
this._endpoint = u.protocol + "//" + u.host + "/api/v1/tracing" + u.pathname + "/spans";
var v = this._cfg._dsn;
this._endpoint = v.scheme + "//" + v.host + "/api/v1/tracing/" + v.projectId + "/spans";
this._headers = {
Authorization: 'Bearer ' + u.username,
Authorization: 'Bearer ' + this._cfg._dsn.token,
'Content-Type': 'application/json',
};
}
Exporter.prototype._filter = function (span) {
SpanExporter.prototype._filter = function (span) {
if (!this._cfg.filters) {

@@ -35,3 +35,3 @@ return true;

};
Exporter.prototype.export = function (spans, resultCallback) {
SpanExporter.prototype.export = function (spans, resultCallback) {
if (this._cfg.disabled) {

@@ -41,28 +41,14 @@ resultCallback({ code: core_1.ExportResultCode.SUCCESS });

}
var m = {};
var uptraceSpans = [];
for (var _i = 0, spans_1 = spans; _i < spans_1.length; _i++) {
var span = spans_1[_i];
var expo = expoSpan(span);
if (!this._filter(expo)) {
continue;
var out = uptraceSpan(span);
if (this._filter(out)) {
uptraceSpans.push(out);
}
var traceId = span.spanContext.traceId;
var expoSpans = m[traceId];
if (!expoSpans) {
expoSpans = [];
m[traceId] = expoSpans;
}
expoSpans.push(expo);
}
var traces = [];
for (var traceId in m) {
traces.push({
id: traceId,
spans: m[traceId],
});
}
cross_fetch_1.default(this._endpoint, {
method: 'POST',
headers: this._headers,
body: JSON.stringify({ traces: traces }),
body: JSON.stringify({ spans: uptraceSpans }),
})

@@ -83,3 +69,3 @@ .then(function (resp) {

};
Exporter.prototype.shutdown = function () {
SpanExporter.prototype.shutdown = function () {
return new Promise(function (resolve) {

@@ -89,30 +75,33 @@ resolve();

};
return Exporter;
return SpanExporter;
}());
exports.Exporter = Exporter;
function expoSpan(span) {
var expo = {
exports.SpanExporter = SpanExporter;
function uptraceSpan(span) {
var out = {
id: span.spanContext.spanId,
parentId: span.parentSpanId,
traceId: span.spanContext.traceId,
name: span.name,
kind: expoKind(span.kind),
kind: uptraceKind(span.kind),
startTime: core_1.hrTimeToTimeStamp(span.startTime),
endTime: core_1.hrTimeToTimeStamp(span.endTime),
statusCode: expoStatus(span.status.code),
statusCode: uptraceStatus(span.status.code),
attrs: span.attributes,
events: expoEvents(span.events),
links: expoLinks(span.links),
events: uptraceEvents(span.events),
links: uptraceLinks(span.links),
resource: span.resource.attributes,
tracer: span.instrumentationLibrary,
};
if (span.parentSpanId) {
out.parentId = span.parentSpanId;
}
if (span.status.message) {
expo.statusMessage = span.status.message;
out.statusMessage = span.status.message;
}
return expo;
return out;
}
function expoEvents(events) {
var expoEvents = [];
function uptraceEvents(events) {
var uptraceEvents = [];
for (var _i = 0, events_1 = events; _i < events_1.length; _i++) {
var event_1 = events_1[_i];
expoEvents.push({
uptraceEvents.push({
name: event_1.name,

@@ -123,9 +112,9 @@ attrs: event_1.attributes,

}
return expoEvents;
return uptraceEvents;
}
function expoLinks(links) {
var expoLinks = [];
function uptraceLinks(links) {
var uptraceLinks = [];
for (var _i = 0, links_1 = links; _i < links_1.length; _i++) {
var link = links_1[_i];
expoLinks.push({
uptraceLinks.push({
traceId: link.context.traceId,

@@ -136,5 +125,5 @@ spanId: link.context.spanId,

}
return expoLinks;
return uptraceLinks;
}
function expoKind(kind) {
function uptraceKind(kind) {
switch (kind) {

@@ -153,3 +142,3 @@ case api_1.SpanKind.SERVER:

}
function expoStatus(code) {
function uptraceStatus(code) {
switch (code) {

@@ -156,0 +145,0 @@ case api_1.StatusCode.OK:

@@ -1,5 +0,5 @@

export * from './config';
export * from './client';
export * from './exporter';
export { Config, createResource } from './config';
export { Client, createClient } from './client';
export { SpanExporter } from './exporter';
export * from './types';
//# sourceMappingURL=index.d.ts.map

@@ -13,6 +13,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./config"), exports);
__exportStar(require("./client"), exports);
__exportStar(require("./exporter"), exports);
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("./types"), exports);
//# sourceMappingURL=index.js.map

@@ -10,3 +10,3 @@ import { Attributes } from '@opentelemetry/api';

statusCode: string;
statusMessage: string;
statusMessage?: string;
attrs: Attributes;

@@ -13,0 +13,0 @@ events: EventData[];

@@ -1,2 +0,2 @@

export declare const VERSION = "0.3.0";
export declare const VERSION = "0.4.0";
//# sourceMappingURL=version.d.ts.map

@@ -5,3 +5,3 @@ "use strict";

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.3.0';
exports.VERSION = '0.4.0';
//# sourceMappingURL=version.js.map
{
"name": "@uptrace/core",
"version": "0.3.0",
"version": "0.4.0",
"description": "Uptrace JS core",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"repository": "uptrace/uptrace-js",
"repository": {
"type": "git",
"url": "git+https://github.com/uptrace/uptrace-js.git",
"directory": "packages/uptrace-core"
},
"scripts": {

@@ -52,22 +56,22 @@ "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts",

"dependencies": {
"@opentelemetry/api": "^0.13.0",
"@opentelemetry/core": "^0.13.0",
"@opentelemetry/tracing": "^0.13.0",
"cross-fetch": "^3.0.5"
"@opentelemetry/api": "^0.16.0",
"@opentelemetry/core": "^0.16.0",
"@opentelemetry/tracing": "^0.16.0",
"cross-fetch": "^3.0.6"
},
"devDependencies": {
"@types/mocha": "8.0.4",
"@types/node": "14.14.10",
"@types/sinon": "^9.0.9",
"@typescript-eslint/eslint-plugin": "4.9.0",
"eslint": "7.15.0",
"@types/mocha": "8.2.0",
"@types/node": "14.14.27",
"@types/sinon": "9.0.10",
"@typescript-eslint/eslint-plugin": "4.15.0",
"eslint": "7.20.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "3.2.0",
"gts": "3.0.3",
"mocha": "8.2.1",
"eslint-plugin-prettier": "3.3.1",
"gts": "3.1.0",
"mocha": "8.3.0",
"nyc": "15.1.0",
"sinon": "^9.2.1",
"sinon": "9.2.4",
"ts-mocha": "8.0.0",
"typescript": "4.1.2"
"typescript": "4.1.5"
}
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc