Documentation
¶
Overview ¶
Copyright The OpenTelemetry Authors SPDX-License-Identifier: Apache-2.0
Package opcua implements a receiver for collecting logs from OPC UA servers. It supports the OPC UA Part 26 LogObject specification for retrieving log records and converts them to OpenTelemetry log format.
Copyright The OpenTelemetry Authors SPDX-License-Identifier: Apache-2.0
Copyright The OpenTelemetry Authors SPDX-License-Identifier: Apache-2.0
Index ¶
Constants ¶
This section is empty.
Variables ¶
var LogRecordExtObjTypeID = ua.NewNumericNodeID(0, 5001)
LogRecordExtObjTypeID is the NodeID used to identify LogRecord ExtensionObjects. Must match the TypeId used by the OPC UA server. The C# test server uses ExpandedNodeId(5001) which encodes as ns=0;i=5001.
var ( // Type is the type of this receiver Type = component.MustNewType("opcua") )
Functions ¶
func NewFactory ¶
NewFactory creates a factory for OPC UA receiver
Types ¶
type AuthConfig ¶
type AuthConfig struct {
// Type is the authentication type (anonymous, username_password, certificate)
Type string `mapstructure:"type"`
// Username for username/password authentication
Username string `mapstructure:"username"`
// Password for username/password authentication
Password string `mapstructure:"password"`
}
AuthConfig defines authentication configuration
type CollectionMode ¶
type CollectionMode string
CollectionMode controls how the receiver gathers log records from the OPC UA server.
const ( // CollectionModePoll uses the GetRecords method call on a fixed interval (default). CollectionModePoll CollectionMode = "poll" // CollectionModeSubscription uses OPC UA Subscriptions / MonitoredItems so the // server pushes notifications when new log records arrive. CollectionModeSubscription CollectionMode = "subscription" )
type Config ¶
type Config struct {
// Endpoint is the OPC UA server endpoint URL (e.g., opc.tcp://localhost:4840)
Endpoint string `mapstructure:"endpoint"`
// SecurityPolicy defines the security policy (None, Basic256, Basic256Sha256, etc.)
SecurityPolicy string `mapstructure:"security_policy"`
// SecurityMode defines the security mode (None, Sign, SignAndEncrypt)
SecurityMode string `mapstructure:"security_mode"`
// Auth contains authentication configuration
Auth AuthConfig `mapstructure:"auth"`
// LogObjectPaths are the paths to browse for LogObject nodes
LogObjectPaths []string `mapstructure:"log_object_paths"`
// CollectionInterval is the interval between log collection attempts (poll mode only)
CollectionInterval time.Duration `mapstructure:"collection_interval"`
// MaxRecordsPerCall is the maximum number of records to retrieve per GetRecords call
MaxRecordsPerCall int `mapstructure:"max_records_per_call"`
// Filter contains log filtering options
Filter FilterConfig `mapstructure:"filter"`
// ConnectionTimeout is the timeout for establishing OPC UA connection
ConnectionTimeout time.Duration `mapstructure:"connection_timeout"`
// RequestTimeout is the timeout for individual OPC UA requests
RequestTimeout time.Duration `mapstructure:"request_timeout"`
// TLS contains TLS/certificate configuration
TLS TLSConfig `mapstructure:"tls"`
// Resource contains resource-level OTel attributes attached to every log record.
Resource ResourceConfig `mapstructure:"resource"`
// CollectionMode selects poll (default) or subscription-based collection.
// poll: periodic GetRecords calls on CollectionInterval
// subscription: OPC UA Subscription / MonitoredItem push delivery
CollectionMode CollectionMode `mapstructure:"collection_mode"`
// Subscription holds options only relevant when CollectionMode == "subscription".
Subscription SubscriptionConfig `mapstructure:"subscription"`
}
Config defines configuration for the OPC UA receiver
type FilterConfig ¶
type FilterConfig struct {
// MinSeverity is the minimum severity level to collect (Trace, Debug, Info, Warn, Error, Fatal)
MinSeverity string `mapstructure:"min_severity"`
// MaxLogRecords is the maximum total number of log records to collect
MaxLogRecords int `mapstructure:"max_log_records"`
}
FilterConfig defines log filtering options
type LogRecordExtObj ¶
type LogRecordExtObj struct {
// Mandatory fields
Time time.Time
Severity uint16
Message string
// Optional fields (bit 0–2)
EventTypeNode *ua.NodeID
SourceNode *ua.NodeID
SourceName string
// TraceContext (bit 3); SpanID == 0 means no trace context
TraceIDBytes [16]byte // raw W3C byte order (same as Guid wire bytes)
SpanID uint64 // big-endian uint64 value of W3C SpanId
ParentSpanID uint64 // 0 for root span
ParentIdentifier string
// AdditionalData (bit 4)
AdditionalData map[string]interface{}
}
LogRecordExtObj is the Go representation of a binary-encoded OPC UA Part 26 LogRecord returned by OPC UA servers implementing the GetRecords method.
Binary field order (OPC UA Part 26 §5.4, all optional fields present when mask=0x1F):
- DateTime – Time (mandatory)
- UInt16 – Severity (mandatory)
- NodeId – EventType (optional, bit 0)
- NodeId – SourceNode (optional, bit 1)
- String – SourceName (optional, bit 2)
- LocalizedText – Message (mandatory)
- TraceContextDataType – TraceContext (optional, bit 3) Guid (16 bytes: Data1 LE-UInt32 + Data2 LE-UInt16 + Data3 LE-UInt16 + Data4 [8]byte) UInt64 – SpanId (0 = absent) UInt64 – ParentSpanId (0 = root span) String – ParentIdentifier
- NameValuePair[] – AdditionalData (optional, bit 4) Int32 – element count (0 = empty, encoded as UInt32 then cast) per element: String (Name) + Variant (Value)
This type is registered with gopcua's ExtensionObject type registry so that it is automatically decoded when received over the wire.
func (*LogRecordExtObj) Decode ¶
func (l *LogRecordExtObj) Decode(b []byte) (int, error)
Decode implements the gopcua codec interface for binary deserialization. Field order matches OPC UA Part 26 §5.4 with all optional fields present (mask=0x1F).
func (*LogRecordExtObj) Encode ¶
func (l *LogRecordExtObj) Encode() ([]byte, error)
Encode implements the gopcua codec interface for binary serialization.
func (*LogRecordExtObj) SpanIDHex ¶
func (l *LogRecordExtObj) SpanIDHex() string
SpanIDHex returns the SpanId as a 16-character lowercase hex string (W3C format).
func (*LogRecordExtObj) String ¶
func (l *LogRecordExtObj) String() string
String returns a human-readable representation.
func (*LogRecordExtObj) TraceIDHex ¶
func (l *LogRecordExtObj) TraceIDHex() string
TraceIDHex returns the TraceId as a 32-character lowercase hex string (W3C format). Returns an empty string when no trace context is present (SpanID == 0).
type OPCUAClient ¶
type OPCUAClient interface {
Connect(ctx context.Context) error
Disconnect(ctx context.Context) error
IsConnected() bool
GetRecords(ctx context.Context, startTime, endTime time.Time, maxRecords int) ([]testdata.OPCUALogRecord, error)
}
OPCUAClient defines the interface for OPC UA client operations This interface allows for easier testing with mock implementations
type ResourceConfig ¶
type ResourceConfig struct {
// ServiceName sets the resource attribute service.name.
// Defaults to "opcua-server" when empty.
ServiceName string `mapstructure:"service_name"`
// ServiceNamespace sets the resource attribute service.namespace.
// Not emitted when empty.
ServiceNamespace string `mapstructure:"service_namespace"`
}
ResourceConfig defines the OTel resource attributes that are emitted with every log record.
type SubscriptionConfig ¶
type SubscriptionConfig struct {
// PublishingInterval is how often the server batches and sends change
// notifications. Lower values give lower latency at the cost of more
// network traffic. Defaults to 1s.
PublishingInterval time.Duration `mapstructure:"publishing_interval"`
// QueueSize is the server-side monitored-item queue depth per node.
// Increase when the server may produce bursts of log records faster
// than the collector can drain them. Defaults to 100.
QueueSize uint32 `mapstructure:"queue_size"`
// ReconnectDelay is how long to wait before re-establishing a broken
// subscription. Defaults to 5s.
ReconnectDelay time.Duration `mapstructure:"reconnect_delay"`
// MaxReconnectAttempts caps the number of reconnect tries before the
// receiver gives up and stops. 0 means unlimited. Defaults to 0.
MaxReconnectAttempts uint32 `mapstructure:"max_reconnect_attempts"`
}
SubscriptionConfig holds options specific to subscription-based collection.
type TLSConfig ¶
type TLSConfig struct {
// CertFile is the path to the client certificate file
CertFile string `mapstructure:"cert_file"`
// KeyFile is the path to the client private key file
KeyFile string `mapstructure:"key_file"`
// CAFile is the path to the CA certificate file
CAFile string `mapstructure:"ca_file"`
// InsecureSkipVerify skips certificate verification (for testing only)
InsecureSkipVerify bool `mapstructure:"insecure_skip_verify"`
}
TLSConfig defines TLS/certificate configuration
type Transformer ¶
type Transformer struct {
// contains filtered or unexported fields
}
Transformer converts OPC UA log records to OpenTelemetry format
func NewTransformer ¶
func NewTransformer(serverEndpoint, serviceName, serviceNamespace string) *Transformer
NewTransformer creates a new transformer
func (*Transformer) TransformLogs ¶
func (t *Transformer) TransformLogs(opcuaRecords []testdata.OPCUALogRecord) plog.Logs
TransformLogs converts OPC UA log records to OpenTelemetry plog.Logs