mirror of
https://github.com/hanzoai/world-zap.git
synced 2026-11-02 12:09:24 +00:00
Real-time Hanzo World feeds over ZAP binary protocol (9-byte header +
JSON payload) fronted by WebSockets at wss://zap.world.hanzo.ai/zap.
IAM bearer auth via Authorization header or ?token= query param.
Validator caches /oauth/userinfo for 5 minutes.
Topics (10): world.events.{all,conflicts,earthquakes,fires},
world.markets.{quotes,crypto}, world.ships.ais, world.aviation.opensky,
world.news.live, world.weather.alerts. Minimum plan enforced per topic.
Tools: subscribe, unsubscribe, list_topics. Admin-only publish for
internal service accounts.
Ingest: streams events from worldmonitor GET /v1/world/events?stream=1,
fans out via bounded-channel hub with drop-on-overflow semantics.
Per-user token bucket rate limits: free 30/min, pro 3000/min, team
15000/min, enterprise 60000/min.
Tests: all packages pass -race (proto, auth, hub, ratelimit, ingest,
handlers). Multi-arch image build wired to hanzoai/.github docker-build
workflow.
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
|
|
"go.opentelemetry.io/otel/sdk/resource"
|
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
|
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
|
)
|
|
|
|
// initOtel configures tracing when OTEL_EXPORTER_OTLP_ENDPOINT is set.
|
|
// Returns a shutdown function that must be called on process exit.
|
|
func initOtel(ctx context.Context, endpoint, serviceName, version string) (func(context.Context) error, error) {
|
|
if endpoint == "" {
|
|
return func(context.Context) error { return nil }, nil
|
|
}
|
|
opts := []otlptracehttp.Option{}
|
|
ep := strings.TrimPrefix(endpoint, "https://")
|
|
ep = strings.TrimPrefix(ep, "http://")
|
|
opts = append(opts, otlptracehttp.WithEndpoint(ep))
|
|
if strings.HasPrefix(endpoint, "http://") {
|
|
opts = append(opts, otlptracehttp.WithInsecure())
|
|
}
|
|
exp, err := otlptracehttp.New(ctx, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res, err := resource.New(ctx,
|
|
resource.WithAttributes(
|
|
semconv.ServiceName(serviceName),
|
|
semconv.ServiceVersion(version),
|
|
),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
tp := sdktrace.NewTracerProvider(
|
|
sdktrace.WithBatcher(exp),
|
|
sdktrace.WithResource(res),
|
|
)
|
|
otel.SetTracerProvider(tp)
|
|
return tp.Shutdown, nil
|
|
}
|