otelcol

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ServerPrompt = `` /* 371-byte string literal not displayed */

ServerPrompt provides instructions for LLMs using the OpenTelemetry Collector toolset.

View Source
const ToolsetName = "observability/otelcol"

Variables

View Source
var (
	ListComponents = tools.ToolDef[ListComponentsOutput]{
		Name:        "otelcol_list_components",
		Description: "List available OpenTelemetry Collector components (receivers, processors, exporters, extensions, connectors) for a given version.",
		Title:       "List OpenTelemetry Collector Components",
		Params: []tools.ParamDef{
			{
				Name:        "version",
				Type:        tools.ParamTypeString,
				Description: "Collector version (e.g., 'v0.100.0'). Defaults to latest available.",
				Required:    false,
			},
		},
		ReadOnly:    true,
		Destructive: false,
		Idempotent:  true,
		OpenWorld:   true,
	}

	GetComponentSchema = tools.ToolDef[GetComponentSchemaOutput]{
		Name:        "otelcol_get_component_schema",
		Description: "Get the JSON schema for an OpenTelemetry Collector component's configuration options.",
		Title:       "Get OpenTelemetry Collector Component Schema",
		Params: []tools.ParamDef{
			{
				Name:        "component_type",
				Type:        tools.ParamTypeString,
				Description: "Component type: " + componentTypeList(),
				Required:    true,
			},
			{
				Name:        "component_name",
				Type:        tools.ParamTypeString,
				Description: "Component name from otelcol_list_components (e.g., 'otlp', 'batch', 'debug')",
				Required:    true,
			},
			{
				Name:        "version",
				Type:        tools.ParamTypeString,
				Description: "Collector version (e.g., 'v0.100.0'). Defaults to latest available.",
				Required:    false,
			},
		},
		ReadOnly:    true,
		Destructive: false,
		Idempotent:  true,
		OpenWorld:   true,
	}

	ValidateConfig = tools.ToolDef[ValidateConfigOutput]{
		Name:        "otelcol_validate_config",
		Description: "Validate an OpenTelemetry Collector component configuration against its JSON schema.",
		Title:       "Validate OpenTelemetry Collector Component Configuration",
		Params: []tools.ParamDef{
			{
				Name:        "component_type",
				Type:        tools.ParamTypeString,
				Description: "Component type: " + componentTypeList(),
				Required:    true,
			},
			{
				Name:        "component_name",
				Type:        tools.ParamTypeString,
				Description: "Component name from otelcol_list_components (e.g., 'otlp', 'batch', 'debug')",
				Required:    true,
			},
			{
				Name:        "config",
				Type:        tools.ParamTypeString,
				Description: "Configuration to validate as YAML or JSON string",
				Required:    true,
			},
			{
				Name:        "format",
				Type:        tools.ParamTypeString,
				Description: "Config format: 'yaml' (default) or 'json'",
				Required:    false,
			},
			{
				Name:        "version",
				Type:        tools.ParamTypeString,
				Description: "Collector version (e.g., 'v0.100.0'). Defaults to latest available.",
				Required:    false,
			},
		},
		ReadOnly:    true,
		Destructive: false,
		Idempotent:  true,
		OpenWorld:   true,
	}

	GetVersions = tools.ToolDef[GetVersionsOutput]{
		Name:        "otelcol_get_versions",
		Description: "List available OpenTelemetry Collector versions and identify the latest.",
		Title:       "Get Available OpenTelemetry Collector Versions",
		Params:      []tools.ParamDef{},
		ReadOnly:    true,
		Destructive: false,
		Idempotent:  true,
		OpenWorld:   true,
	}
)

All tool definitions for OpenTelemetry Collector

Functions

func AllTools

func AllTools() []tools.ToolDefInterface

AllTools returns all otelcol tool definitions.

func GetComponentSchemaHandler

func GetComponentSchemaHandler(ctx context.Context, loader SchemaLoader, input GetComponentSchemaInput) *resultutil.Result

GetComponentSchemaHandler handles getting a component's schema.

func GetVersionsHandler

func GetVersionsHandler(ctx context.Context, loader SchemaLoader, input GetVersionsInput) *resultutil.Result

GetVersionsHandler handles listing available versions.

func ListComponentsHandler

func ListComponentsHandler(ctx context.Context, loader SchemaLoader, input ListComponentsInput) *resultutil.Result

ListComponentsHandler handles the listing of available components.

func ToMCPHandler

func ToMCPHandler[I, O any](
	config *Config,
	buildInput func(map[string]any) I,
	handler func(context.Context, SchemaLoader, I) *resultutil.Result,
) mcp.ToolHandlerFor[map[string]any, O]

ToMCPHandler converts a typed handler function to an MCP tool handler. This allows the otelcol handlers to be used directly with the MCP server.

func ToServerHandler

func ToServerHandler[T any](handler func(params ToolParams) (T, error)) api.ToolHandlerFunc

ToServerHandler converts a typed handler function to an api.ToolHandlerFunc.

func ValidateConfigHandler

func ValidateConfigHandler(ctx context.Context, loader SchemaLoader, input ValidateConfigInput) *resultutil.Result

ValidateConfigHandler handles validating a component configuration.

Types

type ComponentType

type ComponentType string

ComponentType represents the type of OpenTelemetry component.

const (
	ComponentTypeReceiver  ComponentType = "receiver"
	ComponentTypeProcessor ComponentType = "processor"
	ComponentTypeExporter  ComponentType = "exporter"
	ComponentTypeExtension ComponentType = "extension"
	ComponentTypeConnector ComponentType = "connector"
)

func ValidComponentTypes

func ValidComponentTypes() []ComponentType

ValidComponentTypes returns all valid component types.

func (ComponentType) IsValid

func (ct ComponentType) IsValid() bool

IsValid checks if the component type is valid.

type Config

type Config struct {
	// SchemaFS is an embedded filesystem containing component schemas.
	// Expected structure: schemas/0.143.0/receivers/..., schemas/0.144.0/...
	SchemaFS fs.FS
}

Config holds OpenTelemetry Collector toolset configuration.

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig returns the default otelcol configuration using the embedded schemas from redhat-opentelemetry-collector.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that the configuration values are valid.

type GetComponentSchemaInput

type GetComponentSchemaInput struct {
	ComponentType ComponentType `json:"component_type"`
	ComponentName string        `json:"component_name"`
	Version       string        `json:"version,omitempty"`
}

GetComponentSchemaInput defines the input parameters for GetComponentSchemaHandler.

func BuildGetComponentSchemaInput

func BuildGetComponentSchemaInput(args map[string]any) GetComponentSchemaInput

BuildGetComponentSchemaInput builds input from handler arguments.

type GetComponentSchemaOutput

type GetComponentSchemaOutput struct {
	Name    string         `json:"name" jsonschema:"The component name"`
	Type    string         `json:"type" jsonschema:"The component type (receiver, processor, exporter, extension, connector)"`
	Version string         `json:"version" jsonschema:"The OpenTelemetry Collector version"`
	Schema  map[string]any `json:"schema" jsonschema:"The JSON schema for the component configuration"`
}

GetComponentSchemaOutput defines the output schema for the otelcol_get_component_schema tool.

type GetVersionsInput

type GetVersionsInput struct{}

GetVersionsInput defines the input parameters for GetVersionsHandler.

func BuildGetVersionsInput

func BuildGetVersionsInput(_ map[string]any) GetVersionsInput

BuildGetVersionsInput builds input from handler arguments.

type GetVersionsOutput

type GetVersionsOutput struct {
	Versions      []string `json:"versions" jsonschema:"List of available OpenTelemetry Collector versions"`
	LatestVersion string   `json:"latest_version" jsonschema:"The latest available version"`
}

GetVersionsOutput defines the output schema for the otelcol_get_versions tool.

type ListComponentsInput

type ListComponentsInput struct {
	Version string `json:"version,omitempty"`
}

ListComponentsInput defines the input parameters for ListComponentsHandler.

func BuildListComponentsInput

func BuildListComponentsInput(args map[string]any) ListComponentsInput

BuildListComponentsInput builds input from handler arguments.

type ListComponentsOutput

type ListComponentsOutput struct {
	Version    string              `json:"version" jsonschema:"The OpenTelemetry Collector version"`
	Receivers  []string            `json:"receivers" jsonschema:"List of available receiver component names"`
	Processors []string            `json:"processors" jsonschema:"List of available processor component names"`
	Exporters  []string            `json:"exporters" jsonschema:"List of available exporter component names"`
	Extensions []string            `json:"extensions" jsonschema:"List of available extension component names"`
	Connectors []string            `json:"connectors" jsonschema:"List of available connector component names"`
	Components map[string][]string `json:"components" jsonschema:"Map of component type to component names"`
}

ListComponentsOutput defines the output schema for the otelcol_list_components tool.

type SchemaLoader

type SchemaLoader interface {
	GetComponentSchema(componentType schemagen.ComponentType, componentName string, version string) (*schemagen.ComponentSchema, error)
	GetComponentSchemaJSON(componentType schemagen.ComponentType, componentName string, version string) ([]byte, error)
	ListAvailableComponents(version string) (map[schemagen.ComponentType][]string, error)
	ValidateComponentYAML(componentType schemagen.ComponentType, componentName string, version string, yamlData []byte) (*ValidationResult, error)
	ValidateComponentJSON(componentType schemagen.ComponentType, componentName string, version string, jsonData []byte) (*ValidationResult, error)
	GetLatestVersion() (string, error)
	GetAllVersions() ([]string, error)
}

SchemaLoader defines the interface for loading OpenTelemetry Collector schemas.

func NewSchemaLoaderFromFS

func NewSchemaLoaderFromFS(filesystem fs.FS, basePath string) SchemaLoader

NewSchemaLoaderFromFS creates a new SchemaLoader using schemas from the provided filesystem. This allows using an embed.FS or any other fs.FS implementation. The basePath should be the path within the filesystem where version subdirectories are located.

type ToolParams

type ToolParams struct {
	// contains filtered or unexported fields
}

ToolParams contains parameters passed to tool handlers.

type Toolset

type Toolset struct{}

Toolset implements the OpenTelemetry Collector toolset.

func (*Toolset) GetComponentSchemaHandler

func (t *Toolset) GetComponentSchemaHandler(params ToolParams) (GetComponentSchemaOutput, error)

GetComponentSchemaHandlerMethod handles getting a component's schema.

func (*Toolset) GetDescription

func (t *Toolset) GetDescription() string

GetDescription returns a human-readable description of the toolset.

func (*Toolset) GetName

func (t *Toolset) GetName() string

GetName returns the name of the toolset.

func (*Toolset) GetPrompts

func (t *Toolset) GetPrompts() []api.ServerPrompt

GetPrompts returns prompts provided by this toolset.

func (*Toolset) GetResourceTemplates

func (t *Toolset) GetResourceTemplates() []api.ServerResourceTemplate

GetResourceTemplates returns resource templates provided by this toolset.

func (*Toolset) GetResources

func (t *Toolset) GetResources() []api.ServerResource

GetResources returns resources provided by this toolset.

func (*Toolset) GetTools

func (t *Toolset) GetTools(_ api.FilteringProvider) []api.ServerTool

GetTools returns all tools provided by this toolset.

func (*Toolset) GetVersionsHandler

func (t *Toolset) GetVersionsHandler(params ToolParams) (GetVersionsOutput, error)

GetVersionsHandlerMethod handles listing available versions.

func (*Toolset) ListComponentsHandler

func (t *Toolset) ListComponentsHandler(params ToolParams) (ListComponentsOutput, error)

ListComponentsHandlerMethod handles the listing of available components.

func (*Toolset) ValidateConfigHandler

func (t *Toolset) ValidateConfigHandler(params ToolParams) (ValidateConfigOutput, error)

ValidateConfigHandlerMethod handles validating a component configuration.

type ValidateConfigInput

type ValidateConfigInput struct {
	ComponentType ComponentType `json:"component_type"`
	ComponentName string        `json:"component_name"`
	Config        string        `json:"config"`
	Format        string        `json:"format,omitempty"`
	Version       string        `json:"version,omitempty"`
}

ValidateConfigInput defines the input parameters for ValidateConfigHandler.

func BuildValidateConfigInput

func BuildValidateConfigInput(args map[string]any) ValidateConfigInput

BuildValidateConfigInput builds input from handler arguments.

type ValidateConfigOutput

type ValidateConfigOutput struct {
	Valid   bool              `json:"valid" jsonschema:"Whether the configuration is valid"`
	Errors  []ValidationError `json:"errors,omitempty" jsonschema:"List of validation errors if invalid"`
	Version string            `json:"version" jsonschema:"The OpenTelemetry Collector version used for validation"`
}

ValidateConfigOutput defines the output schema for the otelcol_validate_config tool.

type ValidationError

type ValidationError struct {
	Field       string `json:"field" jsonschema:"The field path that has the error"`
	Description string `json:"description" jsonschema:"Description of the validation error"`
	Type        string `json:"type,omitempty" jsonschema:"The error type"`
}

ValidationError represents a single validation error.

type ValidationResult

type ValidationResult struct {
	Valid  bool
	Errors []ValidationError
}

ValidationResult wraps the validation result from JSON schema validation.

Jump to

Keyboard shortcuts

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