Help us shape the future of Go! Take the 2026 Go Developer Survey

tls

package module
v0.0.0-...-eee37f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

README

Volcengine TLS Callbacks

English | 简体中文

callbacks/tls provides a TLS-based observability handler for Eino.

Features

  • Implements github.com/cloudwego/eino/callbacks.Handler
  • Supports session-scoped tracing via SetSession
  • Supports custom callback parsers through WithCallbackDataParser

Installation

go get github.com/cloudwego/eino-ext/callbacks/tls

Quick Start

package main

import (
	"context"
	"log"

	"github.com/cloudwego/eino-ext/callbacks/tls"
	"github.com/cloudwego/eino/callbacks"
)

func main() {
	ctx := tls.SetSession(context.Background(),
		tls.WithSessionID("session-id"),
		tls.WithUserID("user-id"),
	)

	handler, shutdown, err := tls.NewTLSHandler(&tls.TLSConfig{
		TLSEndpoint:       "tls-cn-beijing.volces.com:4317",
		AppName:           "eino-app",
		TLSOTLPHeadersStr: "Authorization=Bearer <token>",
		Release:           "v0.0.1",
	})
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		if shutdown != nil {
			_ = shutdown(ctx)
		}
	}()

	callbacks.AppendGlobalHandlers(handler)

	// Build and run your Eino graph or chain with ctx here.
}

Runnable Demo

The runnable example uses a mock chat model, so it demonstrates both non-streaming and streaming Eino callbacks without LLM provider credentials. Configure the TLS environment variables described in the example README, then run it from this module:

go run ./examples

Configuration

type TLSConfig struct {
	TLSEndpoint       string
	AppName           string
	TLSOTLPHeader     map[string]string
	TLSOTLPHeadersStr string
	Release           string
	TLSExporterEnabled bool
	TLSLogEndpoint    string
	TLSLogRegion      string
	TLSLogTopicID     string
	TLSLogAPIKey      string
	TLSLogAccessKeyID string
	TLSLogAccessKeySecret string
}
TLS exporter, dashboard, and LogApp transport

Set TLSExporterEnabled to use the TLS trace schema. Eino callbacks then emit agent.turn, llm.request, and tool.call spans; they include tls.app.type=eino, session.id, standard model token fields, and tool input/output fields. This is the schema consumed by the Eino LogApp dashboard.

Set the TLSLog* fields to write directly to the Trace Topic through TLS Producer SendLogs. Use either an API key or an AK/SK pair, never hard-code either in source code.

handler, shutdown, err := tls.NewTLSHandler(&tls.TLSConfig{
	AppName:               "Eino",
	TLSExporterEnabled:    true,
	TLSLogEndpoint:        os.Getenv("TLS_LOG_ENDPOINT"),
	TLSLogRegion:          os.Getenv("TLS_LOG_REGION"),
	TLSLogTopicID:         os.Getenv("TLS_LOG_TRACE_TOPIC_ID"),
	TLSLogAPIKey:          os.Getenv("TLS_LOG_API_KEY"), // or TLSLogAccessKeyID/TLSLogAccessKeySecret
})

The equivalent environment-based configuration is TLS_EXPORTER_ENABLED=true together with TLS_APP_NAME, TLS_LOG_ENDPOINT, TLS_LOG_REGION, TLS_LOG_TRACE_TOPIC_ID, and either TLS_LOG_API_KEY or TLS_LOG_AK plus TLS_LOG_SK.

Advanced Usage

handler, shutdown, err := tls.NewTLSHandlerWithOptions(cfg,
	tls.WithCallbackDataParser(customParser),
	tls.WithAggrMessageOutput(true),
)
Manual Spans

Use manual spans for work that does not emit Eino callbacks, such as an ACP protocol request.

ctx = handler.StartSpanWithKind(ctx, "session/prompt", trace.SpanKindServer, map[string]any{
	"rpc.system.name": "jsonrpc",
	"rpc.method":      "session/prompt",
})
defer func() {
	handler.FinishSpanWithError(ctx, nil, err)
}()

References

Documentation

Overview

* Copyright 2025 CloudWeGo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

View Source
const (
	DefaultVersion  = "1.0.1"
	DefaultSpanName = "unset"
)

Variables

This section is empty.

Functions

func NewTLSCallbackHandler

func NewTLSCallbackHandler(config ...*TLSConfig) (handler callbacks.Handler, shutdown func(ctx context.Context) error, err error)

func NewTLSCallbackHandlerFromEnv

func NewTLSCallbackHandlerFromEnv(cfg *TLSConfig) (handler callbacks.Handler, shutdown func(ctx context.Context) error, err error)

NewTLSCallbackHandlerFromEnv keeps the original API shape for callers already passing a prepared config.

func NewTLSCallbackHandlerWithOptions

func NewTLSCallbackHandlerWithOptions(cfg *TLSConfig, opts ...Option) (handler callbacks.Handler, shutdown func(ctx context.Context) error, err error)

func SetSession

func SetSession(ctx context.Context, opts ...SessionOption) context.Context

func ValidateTLSConfig

func ValidateTLSConfig(cfg *TLSConfig) error

Types

type CallbackDataParser

type CallbackDataParser interface {
	ParseInput(ctx context.Context, info *callbacks.RunInfo, input callbacks.CallbackInput) (map[string]any, error)
	ParseOutput(ctx context.Context, info *callbacks.RunInfo, output callbacks.CallbackOutput) (map[string]any, error)
	ParseStreamInput(ctx context.Context, info *callbacks.RunInfo, input *schema.StreamReader[callbacks.CallbackInput]) (map[string]any, error)
	ParseStreamOutput(ctx context.Context, info *callbacks.RunInfo, output *schema.StreamReader[callbacks.CallbackOutput]) (map[string]any, error)
}

CallbackDataParser tag parser for trace Implement CallbackDataParser and replace defaultDataParser by WithCallbackDataParser if needed

func NewDefaultDataParser

func NewDefaultDataParser(enableAggrMessageOutput bool) CallbackDataParser

type Option

type Option func(*options)

func WithAggrMessageOutput

func WithAggrMessageOutput(enable bool) Option

WithAggrMessageOutput controls whether streamed chat model output is merged into one completion message. When disabled, each received chunk is exported as an independent completion message.

func WithCallbackDataParser

func WithCallbackDataParser(parser CallbackDataParser) Option

func WithConcatFunction

func WithConcatFunction[T any](fn func([]T) (T, error)) Option

type RequestInfo

type RequestInfo struct {
	Model string
	// contains filtered or unexported fields
}

type SessionOption

type SessionOption func(*sessionOptions)

func WithSessionID

func WithSessionID(sessionID string) SessionOption

func WithUserID

func WithUserID(userID string) SessionOption

type TLSCallbackHandler

type TLSCallbackHandler struct {
	OtelProvider *opentelemetry.OtelProvider
	AppName      string
	Release      string
	Tracer       trace.Tracer

	TLSExporterEnabled bool
	// contains filtered or unexported fields
}

TLSCallbackHandler implements callbacks.Handler.

func (*TLSCallbackHandler) OnEnd

func (*TLSCallbackHandler) OnEndWithStreamOutput

func (*TLSCallbackHandler) OnError

func (*TLSCallbackHandler) OnStart

func (*TLSCallbackHandler) OnStartWithStreamInput

type TLSConfig

type TLSConfig struct {
	// TLSEndpoint is the TLS OTLP endpoint.
	// Example: "tls-cn-beijing.volces.com:4317"
	TLSEndpoint string

	// AppName is the application name shown in TLS.
	AppName string

	// TLSOTLPHeader contains OTLP export headers.
	TLSOTLPHeader map[string]string

	// TLSOTLPHeadersStr is the comma-separated OTLP headers string.
	TLSOTLPHeadersStr string

	// Release is the version or release identifier.
	Release string

	// TLSExporterEnabled emits the span names and attributes expected by the
	// TLS LogApp dashboard schema. It is opt-in to preserve the
	// existing generic TLS callback behavior for current users.
	TLSExporterEnabled bool

	// TLSLog* configures the TLS Producer SendLogs transport used by the TLS
	// integration. When TLSLogTopicID is empty, the existing OTLP transport is
	// used even if TLSExporterEnabled is enabled.
	TLSLogEndpoint        string
	TLSLogRegion          string
	TLSLogTopicID         string
	TLSLogAPIKey          string
	TLSLogAccessKeyID     string
	TLSLogAccessKeySecret string
}

func LoadTLSConfigFromEnv

func LoadTLSConfigFromEnv() (*TLSConfig, error)

type TLSHandler

type TLSHandler struct {
	*TLSCallbackHandler
}

TLSHandler extends TLSCallbackHandler with manual span controls.

func NewTLSHandler

func NewTLSHandler(config ...*TLSConfig) (*TLSHandler, func(ctx context.Context) error, error)

func NewTLSHandlerFromEnv

func NewTLSHandlerFromEnv(cfg *TLSConfig) (*TLSHandler, func(ctx context.Context) error, error)

NewTLSHandlerFromEnv keeps the original API shape for callers already passing a prepared config.

func NewTLSHandlerWithOptions

func NewTLSHandlerWithOptions(cfg *TLSConfig, opts ...Option) (*TLSHandler, func(ctx context.Context) error, error)

func (*TLSHandler) FinishSpan

func (h *TLSHandler) FinishSpan(ctx context.Context, tracingTags map[string]any) context.Context

func (*TLSHandler) FinishSpanWithError

func (h *TLSHandler) FinishSpanWithError(ctx context.Context, tracingTags map[string]any, err error) context.Context

FinishSpanWithError finishes a manual span and records err when it is non-nil.

func (*TLSHandler) SetSession

func (h *TLSHandler) SetSession(ctx context.Context, sessionID, userID string) context.Context

SetSession stores session attributes in ctx.

func (*TLSHandler) StartSpan

func (h *TLSHandler) StartSpan(ctx context.Context, spanName string, tracingTags map[string]any) context.Context

func (*TLSHandler) StartSpanWithKind

func (h *TLSHandler) StartSpanWithKind(ctx context.Context, spanName string, spanKind trace.SpanKind, tracingTags map[string]any) context.Context

StartSpanWithKind starts a manual span with the specified OpenTelemetry span kind.

type TLSState

type TLSState struct {
	StartTime   time.Time
	Span        trace.Span
	RequestInfo *RequestInfo
	IsRootNode  bool
	// contains filtered or unexported fields
}

type TLSStateKey

type TLSStateKey struct{}

type TLSStreamInputAsyncKey

type TLSStreamInputAsyncKey struct{}

type TLSStreamInputAsyncVal

type TLSStreamInputAsyncVal chan struct{}

Directories

Path Synopsis
Command tls-eino-demo runs a real Eino graph and exports its traces to Volcengine TLS through the eino-ext TLS callback handler.
Command tls-eino-demo runs a real Eino graph and exports its traces to Volcengine TLS through the eino-ext TLS callback handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL