Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/@overeng/utils-dev/src/otelite/test-harness.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from '@effect/vitest'
import { Effect } from 'effect'

import { otlpTracesUrl } from '../node-vitest/Vitest.ts'
import { captureInProcessTrace, OteliteTestHarness } from './test-harness.ts'

describe('OteliteTestHarness', () => {
Expand Down Expand Up @@ -105,6 +106,18 @@ describe('OteliteTestHarness', () => {
expect(process.env.OTELITE_TEST_ENDPOINT).toBe(previousCustomEndpoint)
expect(process.env.OTELITE_TEST_SERVICE).toBe(previousCustomService)
expect(process.env.OTELITE_TEST_EXTRA).toBe(previousExtra)

const previousPerSignalEndpoint = process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
yield* otel.withEnv(
Effect.sync(() => {
expect(process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT).toBe(
otlpTracesUrl(otel.capture.endpoints.http),
)
}),
{ endpointVar: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT' },
)

expect(process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT).toBe(previousPerSignalEndpoint)
}).pipe(Effect.provide(OteliteTestHarness.Default)),
30_000,
)
Expand Down
13 changes: 11 additions & 2 deletions packages/@overeng/utils-dev/src/otelite/test-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ const makeInProcessLayer = (
)
}

const endpointEnvValue = (handle: CaptureHandle, endpointVar?: string): string => {
if (endpointVar === 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT') {
return otlpTracesUrl(handle.endpoints.http)
}
return handle.endpoints.http
}

export class OteliteTestHarness extends Effect.Service<OteliteTestHarness>()(
'@overeng/utils-dev/otelite/OteliteTestHarness',
{
Expand Down Expand Up @@ -166,8 +173,10 @@ export class OteliteTestHarness extends Effect.Service<OteliteTestHarness>()(
envSemaphore.withPermits(1)(
Effect.scoped(
scopedEnv({
[envOptions.endpointVar ?? 'OTEL_EXPORTER_OTLP_ENDPOINT']:
captureHandle.endpoints.http,
[envOptions.endpointVar ?? 'OTEL_EXPORTER_OTLP_ENDPOINT']: endpointEnvValue(
captureHandle,
envOptions.endpointVar,
),
[envOptions.serviceNameVar ?? 'OTEL_SERVICE_NAME']: options.serviceName,
...envOptions.extra,
}).pipe(Effect.zipRight(effect)),
Expand Down
Loading