Skip to content
Open
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
23 changes: 12 additions & 11 deletions apps/agentkit_server_app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"github.com/volcengine/veadk-go/apps/a2a_app"
"github.com/volcengine/veadk-go/apps/simple_app"
"github.com/volcengine/veadk-go/log"
"github.com/volcengine/veadk-go/observability"
"google.golang.org/adk/cmd/launcher"
"google.golang.org/adk/cmd/launcher/web/webui"
"google.golang.org/adk/server/adkrest"
)

)
const serverName = "agentkit server"

type agentkitServerApp struct {
Expand Down Expand Up @@ -63,12 +63,13 @@ func (a *agentkitServerApp) SetupRouters(router *mux.Router, config *apps.RunCon
}

launchConfig := &launcher.Config{
SessionService: config.SessionService,
ArtifactService: config.ArtifactService,
MemoryService: config.MemoryService,
AgentLoader: config.AgentLoader,
A2AOptions: config.A2AOptions,
PluginConfig: config.PluginConfig,
SessionService: config.SessionService,
ArtifactService: config.ArtifactService,
MemoryService: config.MemoryService,
AgentLoader: config.AgentLoader,
A2AOptions: config.A2AOptions,
PluginConfig: config.PluginConfig,
TelemetryOptions: config.TelemetryOptions,
}

// setup webui routers
Expand Down Expand Up @@ -96,9 +97,9 @@ func (a *agentkitServerApp) SetupRouters(router *mux.Router, config *apps.RunCon
// Wrap it with CORS middleware
corsHandler := corsWithArgs(a.GetWebUrl())(apiHandler)

router.Methods("GET", "POST", "DELETE", "OPTIONS").PathPrefix(fmt.Sprintf("%s/", a.ApiPathPrefix)).Handler(
http.StripPrefix(a.ApiPathPrefix, corsHandler),
)
// Wrap with OpenTelemetry instrumentation first, then add to router
wrappedHandler := observability.HTTPMiddleware(http.StripPrefix(a.ApiPathPrefix, corsHandler))
router.Methods("GET", "POST", "DELETE", "OPTIONS").PathPrefix(fmt.Sprintf("%s/", a.ApiPathPrefix)).Handler(wrappedHandler)

log.Infof(" api: you can access API using %s", a.GetAPIPath())
log.Infof(" api: for instance: %s/list-apps", a.GetAPIPath())
Expand Down
16 changes: 10 additions & 6 deletions apps/basic_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ import (
"google.golang.org/adk/plugin"
"google.golang.org/adk/runner"
"google.golang.org/adk/session"
"google.golang.org/adk/telemetry"
)

type RunConfig struct {
SessionService session.Service
ArtifactService artifact.Service
MemoryService memory.Service
AgentLoader agent.Loader
A2AOptions []a2asrv.RequestHandlerOption
PluginConfig runner.PluginConfig
SessionService session.Service
ArtifactService artifact.Service
MemoryService memory.Service
AgentLoader agent.Loader
A2AOptions []a2asrv.RequestHandlerOption
PluginConfig runner.PluginConfig
TelemetryOptions []telemetry.Option
}

func (cfg *RunConfig) AppendObservability() {
Expand All @@ -62,6 +64,8 @@ func (cfg *RunConfig) AppendObservability() {
cfg.PluginConfig.Plugins = append(cfg.PluginConfig.Plugins, observabilityPlugin)
log.Info("Plugin configured")
}

cfg.TelemetryOptions = append(cfg.TelemetryOptions, observability.ADKTelemetryOptions()...)
}

type ApiConfig struct {
Expand Down
6 changes: 0 additions & 6 deletions configs/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ opentelemetry:
endpoint: "http://apmplus-example.com"
api_key: "test-key"
service_name: "test-service"
enable_global_tracer: true
`
var config ObservabilityConfig
err := yaml.Unmarshal([]byte(yamlData), &config)
Expand All @@ -111,18 +110,14 @@ opentelemetry:
assert.Equal(t, "http://apmplus-example.com", config.OpenTelemetry.ApmPlus.Endpoint)
assert.Equal(t, "test-key", config.OpenTelemetry.ApmPlus.APIKey)
assert.Equal(t, "test-service", config.OpenTelemetry.ApmPlus.ServiceName)
assert.True(t, config.OpenTelemetry.EnableGlobalProvider)

assert.Equal(t, "test-service", config.OpenTelemetry.ApmPlus.ServiceName)
assert.True(t, config.OpenTelemetry.EnableGlobalProvider)
}

func TestObservabilityConfig_EnvMapping(t *testing.T) {
os.Setenv("OBSERVABILITY_OPENTELEMETRY_APMPLUS_ENDPOINT", "http://env-endpoint")
os.Setenv("OBSERVABILITY_OPENTELEMETRY_ENABLE_GLOBAL_PROVIDER", "true")
defer func() {
os.Unsetenv("OBSERVABILITY_OPENTELEMETRY_APMPLUS_ENDPOINT")
os.Unsetenv("OBSERVABILITY_OPENTELEMETRY_ENABLE_GLOBAL_PROVIDER")
}()

config := &ObservabilityConfig{}
Expand All @@ -131,7 +126,6 @@ func TestObservabilityConfig_EnvMapping(t *testing.T) {
assert.NotNil(t, config.OpenTelemetry)
assert.NotNil(t, config.OpenTelemetry.ApmPlus)
assert.Equal(t, "http://env-endpoint", config.OpenTelemetry.ApmPlus.Endpoint)
assert.True(t, config.OpenTelemetry.EnableGlobalProvider)
}

func TestObservabilityConfig_Priority(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func SetupVeADKConfig() error {
},
Observability: &ObservabilityConfig{
OpenTelemetry: &OpenTelemetryConfig{
EnableGlobalProvider: true, // use global trace provider by default, like veadk-python
EnableLocalProvider: false, // disable adk-go's local provider
// traces are enabled automatically when at least one trace exporter is configured
},
},
}
Expand Down
34 changes: 9 additions & 25 deletions configs/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import (

const (
// Global
EnvOtelServiceName = "OTEL_SERVICE_NAME"
EnvObservabilityEnableLocalProvider = "OBSERVABILITY_OPENTELEMETRY_ENABLE_LOCAL_PROVIDER"
EnvObservabilityEnableGlobalProvider = "OBSERVABILITY_OPENTELEMETRY_ENABLE_GLOBAL_PROVIDER"
EnvObservabilityEnableMetrics = "OBSERVABILITY_OPENTELEMETRY_ENABLE_METRICS"
EnvOtelServiceName = "OTEL_SERVICE_NAME"
EnvObservabilityEnableMetrics = "OBSERVABILITY_OPENTELEMETRY_ENABLE_METRICS"

// APMPlus
EnvObservabilityOpenTelemetryApmPlusProtocol = "OBSERVABILITY_OPENTELEMETRY_APMPLUS_PROTOCOL"
Expand Down Expand Up @@ -59,9 +57,7 @@ type ObservabilityConfig struct {
}

type OpenTelemetryConfig struct {
EnableLocalProvider bool `yaml:"enable_local_tracer"`
EnableGlobalProvider bool `yaml:"enable_global_tracer"`
EnableMetrics *bool `yaml:"enable_metrics"`
EnableMetrics *bool `yaml:"enable_metrics"`

File *FileConfig `yaml:"file"`
Stdout *StdoutConfig `yaml:"stdout"`
Expand Down Expand Up @@ -231,16 +227,6 @@ func (c *ObservabilityConfig) MapEnvToConfig() {
ot.Stdout.Enable = v == "true"
}

// Global Tracer
if v := utils.GetEnvWithDefault(EnvObservabilityEnableGlobalProvider); v != "" {
ot.EnableGlobalProvider = v == "true"
}

// Local Tracer
if v := utils.GetEnvWithDefault(EnvObservabilityEnableLocalProvider); v != "" {
ot.EnableLocalProvider = v == "true"
}

// Meter Provider
if v := utils.GetEnvWithDefault(EnvObservabilityEnableMetrics); v != "" {
if ot.EnableMetrics == nil {
Expand All @@ -265,14 +251,12 @@ func (c *OpenTelemetryConfig) Clone() *OpenTelemetryConfig {
}

return &OpenTelemetryConfig{
EnableGlobalProvider: c.EnableGlobalProvider,
EnableLocalProvider: c.EnableLocalProvider,
EnableMetrics: c.EnableMetrics,
ApmPlus: c.ApmPlus.Clone(),
CozeLoop: c.CozeLoop.Clone(),
TLS: c.TLS.Clone(),
File: c.File.Clone(),
Stdout: c.Stdout.Clone(),
EnableMetrics: c.EnableMetrics,
ApmPlus: c.ApmPlus.Clone(),
CozeLoop: c.CozeLoop.Clone(),
TLS: c.TLS.Clone(),
File: c.File.Clone(),
Stdout: c.Stdout.Clone(),
}
}

Expand Down
1 change: 1 addition & 0 deletions examples/observability/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func main() {
PluginConfig: runner.PluginConfig{
Plugins: []*plugin.Plugin{observability.NewPlugin()},
},
TelemetryOptions: observability.ADKTelemetryOptions(),
}

l := full.NewLauncher()
Expand Down
48 changes: 25 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ require (
github.com/stretchr/testify v1.11.1
github.com/volcengine/ve-tos-golang-sdk/v2 v2.7.26
github.com/volcengine/volcengine-go-sdk v1.1.53
go.opentelemetry.io/otel v1.39.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0
go.opentelemetry.io/otel v1.40.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.15.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.15.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.16.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.39.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.39.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.39.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.39.0
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.39.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.39.0
go.opentelemetry.io/otel/metric v1.39.0
go.opentelemetry.io/otel/sdk v1.39.0
go.opentelemetry.io/otel/sdk/log v0.15.0
go.opentelemetry.io/otel/sdk/metric v1.39.0
go.opentelemetry.io/otel/trace v1.39.0
golang.org/x/oauth2 v0.32.0
google.golang.org/adk v0.4.0
go.opentelemetry.io/otel/metric v1.40.0
go.opentelemetry.io/otel/sdk v1.40.0
go.opentelemetry.io/otel/sdk/log v0.16.0
go.opentelemetry.io/otel/sdk/metric v1.40.0
go.opentelemetry.io/otel/trace v1.40.0
golang.org/x/oauth2 v0.34.0
google.golang.org/adk v0.5.1-0.20260223191314-02e275dd84a3
google.golang.org/genai v1.40.0
gopkg.in/go-playground/validator.v8 v8.18.2
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -41,6 +42,7 @@ require (
cloud.google.com/go v0.123.0 // indirect
cloud.google.com/go/auth v0.17.0 // indirect
cloud.google.com/go/compute/metadata v0.9.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.31.0 // indirect
github.com/awalterschulze/gographviz v2.0.3+incompatible // indirect
github.com/bluele/gcache v0.0.2 // indirect
github.com/bytedance/sonic v1.14.2 // indirect
Expand All @@ -49,7 +51,7 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/coze-dev/cozeloop-go/spec v0.1.4-0.20250829072213-3812ddbfb735 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.3 // indirect
Expand All @@ -62,7 +64,7 @@ require (
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.6.0 // indirect
Expand All @@ -79,7 +81,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nikolalohinski/gonja/v2 v2.3.1 // indirect
github.com/pkg/errors v0.9.2-0.20201214064552-5dd12d0cfe7f // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smarty/assertions v1.15.0 // indirect
github.com/smartystreets/goconvey v1.8.1 // indirect
Expand All @@ -90,21 +92,21 @@ require (
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
go.mongodb.org/mongo-driver v1.17.6 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.40.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0 // indirect
go.opentelemetry.io/otel/log v0.14.0 // indirect
go.opentelemetry.io/otel/log v0.16.0 // indirect
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
golang.org/x/arch v0.11.0 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.31.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
google.golang.org/grpc v1.77.0 // indirect
google.golang.org/protobuf v1.36.10 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/text v0.33.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect
google.golang.org/grpc v1.78.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
rsc.io/omap v1.2.0 // indirect
Expand Down
Loading