package mcpconv

import "go.opentelemetry.io/otel/semconv/v1.39.0/mcpconv"

Package mcpconv provides types and functionality for OpenTelemetry semantic conventions in the "mcp" namespace.

Index

Types

type ClientOperationDuration

type ClientOperationDuration struct {
	metric.Float64Histogram
}

ClientOperationDuration is an instrument used to record metric values conforming to the "mcp.client.operation.duration" semantic conventions. It represents the duration of the MCP request or notification as observed on the sender from the time it was sent until the response or ack is received.

func NewClientOperationDuration

func NewClientOperationDuration(
	m metric.Meter,
	opt ...metric.Float64HistogramOption,
) (ClientOperationDuration, error)

NewClientOperationDuration returns a new ClientOperationDuration instrument.

func (ClientOperationDuration) AttrErrorType

AttrErrorType returns an optional attribute for the "error.type" semantic convention. It represents the describes a class of error the operation ended with.

func (ClientOperationDuration) AttrGenAIOperationName

AttrGenAIOperationName returns an optional attribute for the "gen_ai.operation.name" semantic convention. It represents the name of the GenAI operation being performed.

func (ClientOperationDuration) AttrGenAIPromptName

func (ClientOperationDuration) AttrGenAIPromptName(val string) attribute.KeyValue

AttrGenAIPromptName returns an optional attribute for the "gen_ai.prompt.name" semantic convention. It represents the name of the prompt or prompt template provided in the request or response.

func (ClientOperationDuration) AttrGenAIToolName

func (ClientOperationDuration) AttrGenAIToolName(val string) attribute.KeyValue

AttrGenAIToolName returns an optional attribute for the "gen_ai.tool.name" semantic convention. It represents the name of the tool utilized by the agent.

func (ClientOperationDuration) AttrJSONRPCProtocolVersion

func (ClientOperationDuration) AttrJSONRPCProtocolVersion(val string) attribute.KeyValue

AttrJSONRPCProtocolVersion returns an optional attribute for the "jsonrpc.protocol.version" semantic convention. It represents the protocol version, as specified in the `jsonrpc` property of the request and its corresponding response.

func (ClientOperationDuration) AttrNetworkProtocolName

func (ClientOperationDuration) AttrNetworkProtocolName(val string) attribute.KeyValue

AttrNetworkProtocolName returns an optional attribute for the "network.protocol.name" semantic convention. It represents the OSI application layer or non-OSI equivalent.

func (ClientOperationDuration) AttrNetworkProtocolVersion

func (ClientOperationDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue

AttrNetworkProtocolVersion returns an optional attribute for the "network.protocol.version" semantic convention. It represents the actual version of the protocol used for network communication.

func (ClientOperationDuration) AttrNetworkTransport

AttrNetworkTransport returns an optional attribute for the "network.transport" semantic convention. It represents the transport protocol used for the MCP session.

func (ClientOperationDuration) AttrProtocolVersion

func (ClientOperationDuration) AttrProtocolVersion(val string) attribute.KeyValue

AttrProtocolVersion returns an optional attribute for the "mcp.protocol.version" semantic convention. It represents the version of the Model Context Protocol used.

func (ClientOperationDuration) AttrRPCResponseStatusCode

func (ClientOperationDuration) AttrRPCResponseStatusCode(val string) attribute.KeyValue

AttrRPCResponseStatusCode returns an optional attribute for the "rpc.response.status_code" semantic convention. It represents the error code from the JSON-RPC response.

func (ClientOperationDuration) AttrResourceURI

func (ClientOperationDuration) AttrResourceURI(val string) attribute.KeyValue

AttrResourceURI returns an optional attribute for the "mcp.resource.uri" semantic convention. It represents the value of the resource uri.

func (ClientOperationDuration) AttrServerAddress

func (ClientOperationDuration) AttrServerAddress(val string) attribute.KeyValue

AttrServerAddress returns an optional attribute for the "server.address" semantic convention. It represents the server domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.

func (ClientOperationDuration) AttrServerPort

func (ClientOperationDuration) AttrServerPort(val int) attribute.KeyValue

AttrServerPort returns an optional attribute for the "server.port" semantic convention. It represents the server port number.

func (ClientOperationDuration) Description

func (ClientOperationDuration) Description() string

Description returns the semantic convention description of the instrument

func (ClientOperationDuration) Inst

Inst returns the underlying metric instrument.

func (ClientOperationDuration) Name

Name returns the semantic convention name of the instrument.

func (ClientOperationDuration) Record

func (m ClientOperationDuration) Record(
	ctx context.Context,
	val float64,
	methodName MethodNameAttr,
	attrs ...attribute.KeyValue,
)

Record records val to the current distribution for attrs.

The methodName is the the name of the request or notification method.

All additional attrs passed are included in the recorded value.

func (ClientOperationDuration) RecordSet

func (m ClientOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set)

RecordSet records val to the current distribution for set.

func (ClientOperationDuration) Unit

Unit returns the semantic convention unit of the instrument

type ClientSessionDuration

type ClientSessionDuration struct {
	metric.Float64Histogram
}

ClientSessionDuration is an instrument used to record metric values conforming to the "mcp.client.session.duration" semantic conventions. It represents the duration of the MCP session as observed on the MCP client.

func NewClientSessionDuration

func NewClientSessionDuration(
	m metric.Meter,
	opt ...metric.Float64HistogramOption,
) (ClientSessionDuration, error)

NewClientSessionDuration returns a new ClientSessionDuration instrument.

func (ClientSessionDuration) AttrErrorType

AttrErrorType returns an optional attribute for the "error.type" semantic convention. It represents the describes a class of error the operation ended with.

func (ClientSessionDuration) AttrJSONRPCProtocolVersion

func (ClientSessionDuration) AttrJSONRPCProtocolVersion(val string) attribute.KeyValue

AttrJSONRPCProtocolVersion returns an optional attribute for the "jsonrpc.protocol.version" semantic convention. It represents the protocol version, as specified in the `jsonrpc` property of the request and its corresponding response.

func (ClientSessionDuration) AttrNetworkProtocolName

func (ClientSessionDuration) AttrNetworkProtocolName(val string) attribute.KeyValue

AttrNetworkProtocolName returns an optional attribute for the "network.protocol.name" semantic convention. It represents the OSI application layer or non-OSI equivalent.

func (ClientSessionDuration) AttrNetworkProtocolVersion

func (ClientSessionDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue

AttrNetworkProtocolVersion returns an optional attribute for the "network.protocol.version" semantic convention. It represents the actual version of the protocol used for network communication.

func (ClientSessionDuration) AttrNetworkTransport

AttrNetworkTransport returns an optional attribute for the "network.transport" semantic convention. It represents the transport protocol used for the MCP session.

func (ClientSessionDuration) AttrProtocolVersion

func (ClientSessionDuration) AttrProtocolVersion(val string) attribute.KeyValue

AttrProtocolVersion returns an optional attribute for the "mcp.protocol.version" semantic convention. It represents the version of the Model Context Protocol used.

func (ClientSessionDuration) AttrServerAddress

func (ClientSessionDuration) AttrServerAddress(val string) attribute.KeyValue

AttrServerAddress returns an optional attribute for the "server.address" semantic convention. It represents the server domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.

func (ClientSessionDuration) AttrServerPort

func (ClientSessionDuration) AttrServerPort(val int) attribute.KeyValue

AttrServerPort returns an optional attribute for the "server.port" semantic convention. It represents the server port number.

func (ClientSessionDuration) Description

func (ClientSessionDuration) Description() string

Description returns the semantic convention description of the instrument

func (ClientSessionDuration) Inst

Inst returns the underlying metric instrument.

func (ClientSessionDuration) Name

Name returns the semantic convention name of the instrument.

func (ClientSessionDuration) Record

func (m ClientSessionDuration) Record(
	ctx context.Context,
	val float64,
	attrs ...attribute.KeyValue,
)

Record records val to the current distribution for attrs.

All additional attrs passed are included in the recorded value.

func (ClientSessionDuration) RecordSet

func (m ClientSessionDuration) RecordSet(ctx context.Context, val float64, set attribute.Set)

RecordSet records val to the current distribution for set.

func (ClientSessionDuration) Unit

Unit returns the semantic convention unit of the instrument

type ErrorTypeAttr

type ErrorTypeAttr string

ErrorTypeAttr is an attribute conforming to the error.type semantic conventions. It represents the describes a class of error the operation ended with.

var (
	// ErrorTypeOther is a fallback error value to be used when the instrumentation
	// doesn't define a custom value.
	ErrorTypeOther ErrorTypeAttr = "_OTHER"
)

type GenAIOperationNameAttr

type GenAIOperationNameAttr string

GenAIOperationNameAttr is an attribute conforming to the gen_ai.operation.name semantic conventions. It represents the name of the GenAI operation being performed.

var (
	// GenAIOperationNameChat is the chat completion operation such as
	// [OpenAI Chat API].
	//
	// [OpenAI Chat API]: https://platform.openai.com/docs/api-reference/chat
	GenAIOperationNameChat GenAIOperationNameAttr = "chat"
	// GenAIOperationNameGenerateContent is the multimodal content generation
	// operation such as [Gemini Generate Content].
	//
	// [Gemini Generate Content]: https://ai.google.dev/api/generate-content
	GenAIOperationNameGenerateContent GenAIOperationNameAttr = "generate_content"
	// GenAIOperationNameTextCompletion is the text completions operation such as
	// [OpenAI Completions API (Legacy)].
	//
	// [OpenAI Completions API (Legacy)]: https://platform.openai.com/docs/api-reference/completions
	GenAIOperationNameTextCompletion GenAIOperationNameAttr = "text_completion"
	// GenAIOperationNameEmbeddings is the embeddings operation such as
	// [OpenAI Create embeddings API].
	//
	// [OpenAI Create embeddings API]: https://platform.openai.com/docs/api-reference/embeddings/create
	GenAIOperationNameEmbeddings GenAIOperationNameAttr = "embeddings"
	// GenAIOperationNameCreateAgent is the create GenAI agent.
	GenAIOperationNameCreateAgent GenAIOperationNameAttr = "create_agent"
	// GenAIOperationNameInvokeAgent is the invoke GenAI agent.
	GenAIOperationNameInvokeAgent GenAIOperationNameAttr = "invoke_agent"
	// GenAIOperationNameExecuteTool is the execute a tool.
	GenAIOperationNameExecuteTool GenAIOperationNameAttr = "execute_tool"
)

type MethodNameAttr

type MethodNameAttr string

MethodNameAttr is an attribute conforming to the mcp.method.name semantic conventions. It represents the name of the request or notification method.

var (
	// MethodNameNotificationsCancelled is the notification cancelling a
	// previously-issued request.
	MethodNameNotificationsCancelled MethodNameAttr = "notifications/cancelled"
	// MethodNameInitialize is the request to initialize the MCP client.
	MethodNameInitialize MethodNameAttr = "initialize"
	// MethodNameNotificationsInitialized is the notification indicating that the
	// MCP client has been initialized.
	MethodNameNotificationsInitialized MethodNameAttr = "notifications/initialized"
	// MethodNameNotificationsProgress is the notification indicating the progress
	// for a long-running operation.
	MethodNameNotificationsProgress MethodNameAttr = "notifications/progress"
	// MethodNamePing is the request to check that the other party is still alive.
	MethodNamePing MethodNameAttr = "ping"
	// MethodNameResourcesList is the request to list resources available on server.
	MethodNameResourcesList MethodNameAttr = "resources/list"
	// MethodNameResourcesTemplatesList is the request to list resource templates
	// available on server.
	MethodNameResourcesTemplatesList MethodNameAttr = "resources/templates/list"
	// MethodNameResourcesRead is the request to read a resource.
	MethodNameResourcesRead MethodNameAttr = "resources/read"
	// MethodNameNotificationsResourcesListChanged is the notification indicating
	// that the list of resources has changed.
	MethodNameNotificationsResourcesListChanged MethodNameAttr = "notifications/resources/list_changed"
	// MethodNameResourcesSubscribe is the request to subscribe to a resource.
	MethodNameResourcesSubscribe MethodNameAttr = "resources/subscribe"
	// MethodNameResourcesUnsubscribe is the request to unsubscribe from resource
	// updates.
	MethodNameResourcesUnsubscribe MethodNameAttr = "resources/unsubscribe"
	// MethodNameNotificationsResourcesUpdated is the notification indicating that a
	// resource has been updated.
	MethodNameNotificationsResourcesUpdated MethodNameAttr = "notifications/resources/updated"
	// MethodNamePromptsList is the request to list prompts available on server.
	MethodNamePromptsList MethodNameAttr = "prompts/list"
	// MethodNamePromptsGet is the request to get a prompt.
	MethodNamePromptsGet MethodNameAttr = "prompts/get"
	// MethodNameNotificationsPromptsListChanged is the notification indicating that
	// the list of prompts has changed.
	MethodNameNotificationsPromptsListChanged MethodNameAttr = "notifications/prompts/list_changed"
	// MethodNameToolsList is the request to list tools available on server.
	MethodNameToolsList MethodNameAttr = "tools/list"
	// MethodNameToolsCall is the request to call a tool.
	MethodNameToolsCall MethodNameAttr = "tools/call"
	// MethodNameNotificationsToolsListChanged is the notification indicating that
	// the list of tools has changed.
	MethodNameNotificationsToolsListChanged MethodNameAttr = "notifications/tools/list_changed"
	// MethodNameLoggingSetLevel is the request to set the logging level.
	MethodNameLoggingSetLevel MethodNameAttr = "logging/setLevel"
	// MethodNameNotificationsMessage is the notification indicating that a message
	// has been received.
	MethodNameNotificationsMessage MethodNameAttr = "notifications/message"
	// MethodNameSamplingCreateMessage is the request to create a sampling message.
	MethodNameSamplingCreateMessage MethodNameAttr = "sampling/createMessage"
	// MethodNameCompletionComplete is the request to complete a prompt.
	MethodNameCompletionComplete MethodNameAttr = "completion/complete"
	// MethodNameRootsList is the request to list roots available on server.
	MethodNameRootsList MethodNameAttr = "roots/list"
	// MethodNameNotificationsRootsListChanged is the notification indicating that
	// the list of roots has changed.
	MethodNameNotificationsRootsListChanged MethodNameAttr = "notifications/roots/list_changed"
	// MethodNameElicitationCreate is the request from the server to elicit
	// additional information from the user via the client.
	MethodNameElicitationCreate MethodNameAttr = "elicitation/create"
)

type NetworkTransportAttr

type NetworkTransportAttr string

NetworkTransportAttr is an attribute conforming to the network.transport semantic conventions. It represents the transport protocol used for the MCP session.

var (
	// NetworkTransportTCP is the TCP.
	NetworkTransportTCP NetworkTransportAttr = "tcp"
	// NetworkTransportUDP is the UDP.
	NetworkTransportUDP NetworkTransportAttr = "udp"
	// NetworkTransportPipe is the named or anonymous pipe.
	NetworkTransportPipe NetworkTransportAttr = "pipe"
	// NetworkTransportUnix is the unix domain socket.
	NetworkTransportUnix NetworkTransportAttr = "unix"
	// NetworkTransportQUIC is the QUIC.
	NetworkTransportQUIC NetworkTransportAttr = "quic"
)

type ServerOperationDuration

type ServerOperationDuration struct {
	metric.Float64Histogram
}

ServerOperationDuration is an instrument used to record metric values conforming to the "mcp.server.operation.duration" semantic conventions. It represents the MCP request or notification duration as observed on the receiver from the time it was received until the result or ack is sent.

func NewServerOperationDuration

func NewServerOperationDuration(
	m metric.Meter,
	opt ...metric.Float64HistogramOption,
) (ServerOperationDuration, error)

NewServerOperationDuration returns a new ServerOperationDuration instrument.

func (ServerOperationDuration) AttrErrorType

AttrErrorType returns an optional attribute for the "error.type" semantic convention. It represents the describes a class of error the operation ended with.

func (ServerOperationDuration) AttrGenAIOperationName

AttrGenAIOperationName returns an optional attribute for the "gen_ai.operation.name" semantic convention. It represents the name of the GenAI operation being performed.

func (ServerOperationDuration) AttrGenAIPromptName

func (ServerOperationDuration) AttrGenAIPromptName(val string) attribute.KeyValue

AttrGenAIPromptName returns an optional attribute for the "gen_ai.prompt.name" semantic convention. It represents the name of the prompt or prompt template provided in the request or response.

func (ServerOperationDuration) AttrGenAIToolName

func (ServerOperationDuration) AttrGenAIToolName(val string) attribute.KeyValue

AttrGenAIToolName returns an optional attribute for the "gen_ai.tool.name" semantic convention. It represents the name of the tool utilized by the agent.

func (ServerOperationDuration) AttrJSONRPCProtocolVersion

func (ServerOperationDuration) AttrJSONRPCProtocolVersion(val string) attribute.KeyValue

AttrJSONRPCProtocolVersion returns an optional attribute for the "jsonrpc.protocol.version" semantic convention. It represents the protocol version, as specified in the `jsonrpc` property of the request and its corresponding response.

func (ServerOperationDuration) AttrNetworkProtocolName

func (ServerOperationDuration) AttrNetworkProtocolName(val string) attribute.KeyValue

AttrNetworkProtocolName returns an optional attribute for the "network.protocol.name" semantic convention. It represents the OSI application layer or non-OSI equivalent.

func (ServerOperationDuration) AttrNetworkProtocolVersion

func (ServerOperationDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue

AttrNetworkProtocolVersion returns an optional attribute for the "network.protocol.version" semantic convention. It represents the actual version of the protocol used for network communication.

func (ServerOperationDuration) AttrNetworkTransport

AttrNetworkTransport returns an optional attribute for the "network.transport" semantic convention. It represents the transport protocol used for the MCP session.

func (ServerOperationDuration) AttrProtocolVersion

func (ServerOperationDuration) AttrProtocolVersion(val string) attribute.KeyValue

AttrProtocolVersion returns an optional attribute for the "mcp.protocol.version" semantic convention. It represents the version of the Model Context Protocol used.

func (ServerOperationDuration) AttrRPCResponseStatusCode

func (ServerOperationDuration) AttrRPCResponseStatusCode(val string) attribute.KeyValue

AttrRPCResponseStatusCode returns an optional attribute for the "rpc.response.status_code" semantic convention. It represents the error code from the JSON-RPC response.

func (ServerOperationDuration) AttrResourceURI

func (ServerOperationDuration) AttrResourceURI(val string) attribute.KeyValue

AttrResourceURI returns an optional attribute for the "mcp.resource.uri" semantic convention. It represents the value of the resource uri.

func (ServerOperationDuration) Description

func (ServerOperationDuration) Description() string

Description returns the semantic convention description of the instrument

func (ServerOperationDuration) Inst

Inst returns the underlying metric instrument.

func (ServerOperationDuration) Name

Name returns the semantic convention name of the instrument.

func (ServerOperationDuration) Record

func (m ServerOperationDuration) Record(
	ctx context.Context,
	val float64,
	methodName MethodNameAttr,
	attrs ...attribute.KeyValue,
)

Record records val to the current distribution for attrs.

The methodName is the the name of the request or notification method.

All additional attrs passed are included in the recorded value.

func (ServerOperationDuration) RecordSet

func (m ServerOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set)

RecordSet records val to the current distribution for set.

func (ServerOperationDuration) Unit

Unit returns the semantic convention unit of the instrument

type ServerSessionDuration

type ServerSessionDuration struct {
	metric.Float64Histogram
}

ServerSessionDuration is an instrument used to record metric values conforming to the "mcp.server.session.duration" semantic conventions. It represents the duration of the MCP session as observed on the MCP server.

func NewServerSessionDuration

func NewServerSessionDuration(
	m metric.Meter,
	opt ...metric.Float64HistogramOption,
) (ServerSessionDuration, error)

NewServerSessionDuration returns a new ServerSessionDuration instrument.

func (ServerSessionDuration) AttrErrorType

AttrErrorType returns an optional attribute for the "error.type" semantic convention. It represents the describes a class of error the operation ended with.

func (ServerSessionDuration) AttrJSONRPCProtocolVersion

func (ServerSessionDuration) AttrJSONRPCProtocolVersion(val string) attribute.KeyValue

AttrJSONRPCProtocolVersion returns an optional attribute for the "jsonrpc.protocol.version" semantic convention. It represents the protocol version, as specified in the `jsonrpc` property of the request and its corresponding response.

func (ServerSessionDuration) AttrNetworkProtocolName

func (ServerSessionDuration) AttrNetworkProtocolName(val string) attribute.KeyValue

AttrNetworkProtocolName returns an optional attribute for the "network.protocol.name" semantic convention. It represents the OSI application layer or non-OSI equivalent.

func (ServerSessionDuration) AttrNetworkProtocolVersion

func (ServerSessionDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue

AttrNetworkProtocolVersion returns an optional attribute for the "network.protocol.version" semantic convention. It represents the actual version of the protocol used for network communication.

func (ServerSessionDuration) AttrNetworkTransport

AttrNetworkTransport returns an optional attribute for the "network.transport" semantic convention. It represents the transport protocol used for the MCP session.

func (ServerSessionDuration) AttrProtocolVersion

func (ServerSessionDuration) AttrProtocolVersion(val string) attribute.KeyValue

AttrProtocolVersion returns an optional attribute for the "mcp.protocol.version" semantic convention. It represents the version of the Model Context Protocol used.

func (ServerSessionDuration) Description

func (ServerSessionDuration) Description() string

Description returns the semantic convention description of the instrument

func (ServerSessionDuration) Inst

Inst returns the underlying metric instrument.

func (ServerSessionDuration) Name

Name returns the semantic convention name of the instrument.

func (ServerSessionDuration) Record

func (m ServerSessionDuration) Record(
	ctx context.Context,
	val float64,
	attrs ...attribute.KeyValue,
)

Record records val to the current distribution for attrs.

All additional attrs passed are included in the recorded value.

func (ServerSessionDuration) RecordSet

func (m ServerSessionDuration) RecordSet(ctx context.Context, val float64, set attribute.Set)

RecordSet records val to the current distribution for set.

func (ServerSessionDuration) Unit

Unit returns the semantic convention unit of the instrument

Source Files

metric.go

Version
v1.43.0 (latest)
Published
Apr 3, 2026
Platform
linux/amd64
Imports
5 packages
Last checked
1 hour ago

Tools for package owners.