Skip to content

Commit 4f5be46

Browse files
committed
added apiKey and headers property to traceo client
1 parent 8ce2a26 commit 4f5be46

6 files changed

Lines changed: 22 additions & 7 deletions

File tree

lib/core/http.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ export class HttpModule {
6868
}
6969

7070
private requestHeaders() {
71-
if (this.method != "POST") return {};
71+
const headers = Client.client.headers;
72+
const baseHeaders = {
73+
...headers,
74+
};
75+
if (this.method !== "POST") return baseHeaders;
7276
return {
7377
headers: {
7478
"Content-Type": "application/json",
79+
...baseHeaders,
7580
},
7681
};
7782
}

lib/core/version.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
const pkg = require("../package.json");
1+
// TODO:
2+
// const pkg = require("../package.json");
23

3-
export const TRACEO_SDK_VERSION = pkg.version;
4+
export const TRACEO_SDK_VERSION = "0.3.31";

lib/node/client.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { isEmpty } from "../core/is";
2+
import { TRACEO_SDK_VERSION } from "../core/version";
23
import { TraceoOptions } from "../transport/options";
34
import { Logger } from "./logger";
45
import { MetricsProbe } from "./metrics";
56
import { RuntimeData } from "./metrics/runtime-data";
67

78
export class Client {
8-
private options: TraceoOptions;
9+
public headers: { [key: string]: any };
910

11+
private options: TraceoOptions;
1012
private metricsProbe: MetricsProbe;
1113
private runtimeData: RuntimeData;
1214

@@ -16,6 +18,11 @@ export class Client {
1618
this.configGlobalClient();
1719

1820
this.options = options;
21+
this.headers = {
22+
"x-sdk-name": "Node.js",
23+
"x-sdk-version": TRACEO_SDK_VERSION,
24+
"x-sdk-key": this.options.apiKey,
25+
};
1926
this.metricsProbe = new MetricsProbe(this.options);
2027

2128
this.logger = new Logger();

lib/transport/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export interface TraceoOptions {
2-
appId: number;
2+
apiKey: string;
3+
appId: string;
34
offline?: boolean;
45
url: string;
56
/*

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "traceo-sdk",
3-
"version": "0.3.26",
3+
"version": "0.3.31",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

test/client.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ describe("TraceClient", () => {
55
let client: Client;
66

77
const clientOptions: TraceoOptions = {
8-
appId: 35,
8+
apiKey: "sasdasdads",
9+
appId: "92873498234",
910
url: "/",
1011
collectMetrics: true,
1112
scrapMetricsInterval: 15,

0 commit comments

Comments
 (0)