Skip to content

Commit

Permalink
fix: work with remote server (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomer-friedman committed May 11, 2023
1 parent a0fd1e2 commit d219a40
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion jest-opentelemetry.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
timeout: 2000,
useRemoteOtelReceiver: false,
useLocalOtelReceiver: true, // default (false) is to use traceloop backend
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"start:test-servers": "lerna run --scope @traceloop/test-servers start",
"docker:instrument-opentelemetry": "docker build -f packages/instrument-opentelemetry/Dockerfile . -t instrument-opentelemetry",
"docker:test-servers": "docker build -f packages/test-servers/Dockerfile . -t test-servers",
"test": "jest",
"test-ci": "concurrently -k --success \"command-1\" --hide 0 \"npm:start:test-servers\" \"npm:test\"",
"test": "TRACELOOP_URL='http://localhost:4123/v1/traces' jest",
"test-ci": "TRACELOOP_URL='http://localhost:4123/v1/traces' concurrently -k --success \"command-1\" --hide 0 \"npm:start:test-servers\" \"npm:test\"",
"release": "npm run build && lerna publish --conventional-commits --no-private"
},
"workspaces": [
Expand Down
6 changes: 3 additions & 3 deletions packages/expect-opentelemetry/src/trace-loop/fetch-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export interface FetchTracesConfig {
pollInterval: number;
awaitAllSpansInTraceTimeout: number;
url: string;
customerId: string;
apiKey: string;
}

export const fetchTracesConfigBase: FetchTracesConfig = {
maxPollTime: 9000,
pollInterval: 1000,
awaitAllSpansInTraceTimeout: 2000,
url: 'http://localhost:4123/v1/traces',
customerId: 'local',
url: process.env.TRACELOOP_URL || 'https://api.traceloop.dev/v1/traces',
apiKey: process.env.TRACELOOP_API_KEY || 'none',
};

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/expect-opentelemetry/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import http from 'http';
import https from 'https';
import { opentelemetry } from '@traceloop/otel-proto';
import { FetchTracesConfig } from './trace-loop/fetch-traces';

Expand Down Expand Up @@ -88,7 +89,8 @@ export function httpGetBinary(
): Promise<Buffer> {
const url = `${config.url}/${traceloopId}`;
return new Promise((resolve, reject) => {
http.get(url, { headers: { Authorization: config.customerId } }, (res) => {
const method = config.url.includes('https') ? https : http;
method.get(url, { headers: { Authorization: config.apiKey } }, (res) => {
const { statusCode } = res;

if (!statusCode || statusCode < 200 || statusCode >= 300) {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment-otel/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function setup(jestConfig: JestConfig = {}) {
didAlreadyRunInWatchMode = true;
}

if (config.useRemoteOtelReceiver) {
if (!config?.useLocalOtelReceiver) {
return;
}

Expand Down

0 comments on commit d219a40

Please sign in to comment.