mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Full module path rebrand from Temporal to Hanzo Tasks: - go.mod module: github.com/hanzoai/tasks - All internal Go imports updated (1906 files) - cmd/server renamed to cmd/tasksd - Binary name: tasksd (was temporal-server) - Docker images: hanzoai/tasks (was temporalio/server) - README rewritten with Hanzo Tasks branding - LLM.md created with integration notes - Makefile, goreleaser, CI workflows updated - go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos) Fork of Temporal.io (MIT license).
101 lines
3.0 KiB
Go
101 lines
3.0 KiB
Go
package telemetry_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/hanzoai/tasks/common/primitives"
|
|
"github.com/hanzoai/tasks/common/telemetry"
|
|
)
|
|
|
|
func TestSupplementTraceExportersFromEnv(t *testing.T) {
|
|
t.Run("when env variable specifies valid OTEL exporter type, add exporter", func(t *testing.T) {
|
|
exporters, err := telemetry.SpanExportersFromEnv(
|
|
func(key string) (string, bool) {
|
|
if key == telemetry.OtelTracesExporterTypesEnvKey {
|
|
return string(telemetry.OtelTracesOtlpExporterType), true
|
|
}
|
|
return "", false
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
require.Len(t, exporters, 1)
|
|
})
|
|
|
|
t.Run("when env variable specifies valid OTEL exporter type but invalid protocol, return error", func(t *testing.T) {
|
|
exporters, err := telemetry.SpanExportersFromEnv(
|
|
func(key string) (string, bool) {
|
|
switch key {
|
|
case telemetry.OtelTracesExporterTypesEnvKey:
|
|
return string(telemetry.OtelTracesOtlpExporterType), true
|
|
case telemetry.OtelExporterOtlpTracesProtocolEnvKey:
|
|
return "invalid", true
|
|
}
|
|
return "", false
|
|
})
|
|
|
|
require.EqualError(t, err, "unsupported OTEL exporter protocol: OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=invalid")
|
|
require.Empty(t, exporters)
|
|
})
|
|
|
|
t.Run("when env variable is specified but exporter type is not supported, return error", func(t *testing.T) {
|
|
exporters, err := telemetry.SpanExportersFromEnv(
|
|
func(key string) (string, bool) {
|
|
if key == telemetry.OtelTracesExporterTypesEnvKey {
|
|
return fmt.Sprintf("%v,%v", telemetry.OtelTracesOtlpExporterType, "nonsense"), true
|
|
}
|
|
return "", false
|
|
})
|
|
|
|
require.EqualError(t, err, "unsupported OTEL exporter: OTEL_TRACES_EXPORTER=nonsense")
|
|
require.Empty(t, exporters)
|
|
})
|
|
|
|
t.Run("when not specified, do not create any exporters", func(t *testing.T) {
|
|
exporters, err := telemetry.SpanExportersFromEnv(
|
|
func(key string) (string, bool) {
|
|
return "", false
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
require.Empty(t, exporters)
|
|
})
|
|
}
|
|
|
|
func TestResourceServiceName(t *testing.T) {
|
|
t.Run("when env variable is specified, use custom service name prefix", func(t *testing.T) {
|
|
require.Equal(t,
|
|
"PREFIX.matching",
|
|
telemetry.ResourceServiceName(primitives.MatchingService, func(key string) (string, bool) {
|
|
require.Equal(t, telemetry.OtelServiceNameEnvKey, key)
|
|
return "PREFIX", true
|
|
}),
|
|
)
|
|
})
|
|
|
|
t.Run("when not specified, use default prefix", func(t *testing.T) {
|
|
require.Equal(t,
|
|
"io.temporal.history",
|
|
telemetry.ResourceServiceName(primitives.HistoryService, func(key string) (string, bool) {
|
|
return "", false
|
|
}),
|
|
)
|
|
})
|
|
|
|
t.Run("always use single service name for internal frontend", func(t *testing.T) {
|
|
require.Equal(t,
|
|
"PREFIX.frontend",
|
|
telemetry.ResourceServiceName(primitives.InternalFrontendService, func(key string) (string, bool) {
|
|
return "PREFIX", true
|
|
}),
|
|
)
|
|
require.Equal(t,
|
|
"io.temporal.frontend",
|
|
telemetry.ResourceServiceName(primitives.InternalFrontendService, func(key string) (string, bool) {
|
|
return "", false
|
|
}),
|
|
)
|
|
})
|
|
}
|