Skip to main content

Documentation Index

Fetch the complete documentation index at: https://otel.fyi/llms.txt

Use this file to discover all available pages before exploring further.

Sqlserver Receiver

Status Available in: contrib Maintainers: @sincejune, @crobert-1 Source: opentelemetry-collector-contrib

Supported Telemetry

Logs Metrics

Overview

Required Permissions

Windows Performance Counters

Make sure to run the collector as administrator in order to collect all performance counters for metrics.

Direct Connection

When configured to directly connect to the SQL Server instance, the user must have the following permissions:
  1. At least one of the following permissions:
  • CREATE DATABASE
  • ALTER ANY DATABASE
  • VIEW ANY DATABASE
  1. Permission to view server state:
    • SQL Server pre-2022: VIEW SERVER STATE
    • SQL Server 2022 and later: VIEW SERVER PERFORMANCE STATE

Configuration

The following is a generic configuration that can be used for the default logs and metrics scraped by the SQL Server receiver. A basic explanation on some of the fields has also been provided. For more information, please reference the following section.
sqlserver:
  collection_interval: 10s                     # interval for overall collection
  instance_name: CustomInstance
  username: myusername
  password: mypassword
  server: sqlserver.address
  port: 1433
  events:
    db.server.query_sample:
      enabled: true
    db.server.top_query:
      enabled: true
  top_query_collection:                        # this collection exports the most expensive queries as logs
    lookback_time: 60s                         # which time window should we look for the top queries
    max_query_sample_count: 1000               # maximum number query we store in cache for top queries.
    top_query_count: 250                       # The maximum number of active queries to report in a single run.
    collection_interval: 60s                   # collection interval for top query collection specifically
  query_sample_collection:                     # this collection exports the currently (relate to the query time) executing queries as logs
    max_rows_per_query: 100                    # the maximum number of samples to return for one single query.
The following settings are optional:
  • collection_interval (default = 10s): The interval at which metrics should be emitted by this receiver.
  • instance_name (optional): The instance name identifies the specific SQL Server instance being monitored. If unspecified, metrics will be scraped from all instances. If configured, the computer_name must also be set when running on Windows.
Direct connection options (optional, but all must be specified to enable):
  • username: The username used to connect to the SQL Server instance.
  • password: The password used to connect to the SQL Server instance.
  • server: IP Address or hostname of SQL Server instance to connect to.
  • port: Port of the SQL Server instance to connect to.
For finer control over the direct connection use the datasource, a.k.a. the “connection string”, instead. Note: it can’t be used in conjunction with the username, password, server and port options. Windows-specific options:
  • computer_name (optional): The computer name identifies the SQL Server name or IP address of the computer being monitored. If specified, instance_name is also required to be defined. This option is ignored in non-Windows environments.
Top-Query collection specific options (only useful when top-query collection are enabled):
  • lookback_time (optional, example = 60s, default = 2 * collection_interval): The time window (in second) in which to query for top queries.
    • Queries that were finished execution outside the lookback window are not included in the collection. Increasing the lookback window (in seconds) will be useful for capturing long-running queries.
  • max_query_sample_count (optional, example = 5000, default = 1000): The maximum number of records to fetch in a single run.
  • top_query_count: (optional, example = 100, default = 250): The maximum number of active queries to report (to the next consumer) in a single run.
  • collection_interval: (optional, default = 60s): The interval at which top queries should be emitted by this receiver.
    • This value can only guarantee that the top queries are collected at most once in this interval.
      • For instance, you have global collection_interval as 10s and top_query_collection.collection_interval as 60s.
        • In this case, the default receiver scraper will still try to run in every 10 seconds.
        • However, the top queries collection will only run after 60 seconds have passed since the last collection.
      • For instance, you have global collection_interval as 10s and top_query_collection.collection_interval as 5s.
        • In this case, top_query_collection.collection_internal will make no effects to the collection
Query sample collection related options (only useful when query sample is enabled)
  • max_rows_per_query: (optional, default = 100) use this to limit rows returned by the sampling query. Example:
    receivers:
      sqlserver:
        collection_interval: 10s
      sqlserver/1:
        collection_interval: 5s
        username: sa
        password: securepassword
        server: 0.0.0.0
        port: 1433
When a named instance is used on Windows, a computer name and an instance name must be specified. Example with named instance:
    receivers:
      sqlserver:
        collection_interval: 10s
        computer_name: CustomServer
        instance_name: CustomInstance
        resource_attributes:
          sqlserver.computer.name:
            enabled: true
          sqlserver.instance.name:
            enabled: true
The full list of settings exposed for this receiver are documented in config.go with detailed sample configurations in testdata/config.yaml. Top query collection enabled:
    receivers:
      sqlserver:
        collection_interval: 5s
        username: sa
        password: securepassword
        server: 0.0.0.0
        port: 1433
        top_query_collection:
          lookback_time: 60s
          max_query_sample_count: 1000
          top_query_count: 200
        query_sample_collection:
          max_rows_per_query: 1450

Feature Gate

A new feature gate was added in v0.129.0 for removing the server.address and server.port resource attributes, as they are not identified as resources attributes in the semantic conventions. To enable it, pass the following argument to the Collector:
--feature-gates=receiver.sqlserver.RemoveServerResourceAttribute

Metrics

Details about the metrics produced by this receiver can be found in documentation.md

Logs

Details about the logs produced by this receiver can be found in logs-documentation.md

Known issues

SQL Server docker users may run into an issue that the collector fails to parse certificate from server due to x509: negative serial number. That’s because we adopted Go 1.23 starting from contrib v0.121.0:
Before Go 1.23, ParseCertificate accepted certificates with negative serial numbers. This behavior can be restored by including “x509negativeserial=1” in the GODEBUG environment variable. references:
  1. https://pkg.go.dev/crypto/x509#ParseCertificate
  2. https://github.com/microsoft/mssql-docker/issues/895

Troubleshooting

service.instance.id is unknown:1433

In a rare case, the service.instance.id resource attribute is set to unknown:1433. This is because the receiver is unable to parse and compute the service.instance.id resource attribute. You can file an issue that includes your configuration to help us investigate the issue.

Metrics

Metric NameDescriptionUnitTypeAttributes
sqlserver.batch.request.rateNumber of batch requests received by SQL Server.{requests}/sGauge
sqlserver.batch.sql_compilation.rateNumber of SQL compilations needed.{compilations}/sGauge
sqlserver.batch.sql_recompilation.rateNumber of SQL recompilations needed.{compilations}/sGauge
sqlserver.computer.uptimeComputer uptime.{seconds}Gauge
sqlserver.cpu.countNumber of CPUs.{CPUs}Gauge
sqlserver.database.backup_or_restore.rateTotal number of backups/restores.“{backups_or_restores}/s”Gauge
sqlserver.database.countThe number of databases{databases}Gaugedatabase.status
sqlserver.database.execution.errorsNumber of execution errors.“{errors}”Gauge
sqlserver.database.full_scan.rateThe number of unrestricted full table or index scans.{scans}/sGauge
sqlserver.database.ioThe number of bytes of I/O on this file.ByCounterphysical_filename, logical_filename, file_type, direction
sqlserver.database.latencyTotal time that the users waited for I/O issued on this file.sCounterphysical_filename, logical_filename, file_type, direction
sqlserver.database.operationsThe number of operations issued on the file.{operations}Counterphysical_filename, logical_filename, file_type, direction
sqlserver.database.tempdb.spaceTotal free space in temporary DB.“KB”UpDownCountertempdb.state
sqlserver.database.tempdb.version_store.sizeTempDB version store size.“KB”Gauge
sqlserver.deadlock.rateTotal number of deadlocks.“{deadlocks}/s”Gauge
sqlserver.index.search.rateTotal number of index searches.“{searches}/s”Gauge
sqlserver.lock.timeout.rateTotal number of lock timeouts.“{timeouts}/s”Gauge
sqlserver.lock.wait.countCumulative count of lock waits that occurred.{wait}Counter
sqlserver.lock.wait.rateNumber of lock requests resulting in a wait.{requests}/sGauge
sqlserver.lock.wait_time.avgAverage wait time for all lock requests that had to wait.msGauge
sqlserver.login.rateTotal number of logins.“{logins}/s”Gauge
sqlserver.logout.rateTotal number of logouts.“{logouts}/s”Gauge
sqlserver.memory.grants.pending.countTotal number of memory grants pending.“{grants}”UpDownCounter
sqlserver.memory.usageTotal memory in use.“KB”UpDownCounter
sqlserver.os.wait.durationTotal wait time for this wait typesCounterwait.category, wait.type
sqlserver.page.buffer_cache.free_list.stalls.rateNumber of free list stalls.“{stalls}/s”Gauge
sqlserver.page.buffer_cache.hit_ratioPages found in the buffer pool without having to read from disk.%Gauge
sqlserver.page.checkpoint.flush.rateNumber of pages flushed by operations requiring dirty pages to be flushed.{pages}/sGauge
sqlserver.page.lazy_write.rateNumber of lazy writes moving dirty pages to disk.{writes}/sGauge
sqlserver.page.life_expectancyTime a page will stay in the buffer pool.sGaugeperformance_counter.object_name
sqlserver.page.lookup.rateTotal number of page lookups.“{lookups}/s”Gauge
sqlserver.page.operation.rateNumber of physical database page operations issued.{operations}/sGaugepage.operations
sqlserver.page.split.rateNumber of pages split as a result of overflowing index pages.{pages}/sGauge
sqlserver.processes.blockedThe number of processes that are currently blocked{processes}Gauge
sqlserver.replica.data.rateThroughput rate of replica data.By/sGaugereplica.direction
sqlserver.resource_pool.disk.operationsThe rate of operations issued.{operations}/sGaugedirection
sqlserver.resource_pool.disk.throttled.read.rateThe number of read operations that were throttled in the last second{reads}/sGauge
sqlserver.resource_pool.disk.throttled.write.rateThe number of write operations that were throttled in the last second{writes}/sGauge
sqlserver.table.countThe number of tables.“{tables}”UpDownCountertable.state, table.status
sqlserver.transaction.delayTime consumed in transaction delays.msUpDownCounter
sqlserver.transaction.mirror_write.rateTotal number of mirror write transactions.“{transactions}/s”Gauge
sqlserver.transaction.rateNumber of transactions started for the database (not including XTP-only transactions).{transactions}/sGauge
sqlserver.transaction.write.rateNumber of transactions that wrote to the database and committed.{transactions}/sGauge
sqlserver.transaction_log.flush.data.rateTotal number of log bytes flushed.By/sGauge
sqlserver.transaction_log.flush.rateNumber of log flushes.{flushes}/sGauge
sqlserver.transaction_log.flush.wait.rateNumber of commits waiting for a transaction log flush.{commits}/sGauge
sqlserver.transaction_log.growth.countTotal number of transaction log expansions for a database.{growths}Counter
sqlserver.transaction_log.shrink.countTotal number of transaction log shrinks for a database.{shrinks}Counter
sqlserver.transaction_log.usagePercent of transaction log space used.%Gauge
sqlserver.user.connection.countNumber of users connected to the SQL Server.{connections}Gauge

Attributes

Attribute NameDescriptionTypeValues
client.addressHostname or address of the client.string
client.portTCP port used by the client.int
database.statusThe current status of a databasestringonline, restoring, recovering, pending_recovery, suspect, offline
db.namespaceThe database name.string
db.query.textThe text of the database query being executed.string
db.system.nameThe database management system (DBMS) product as identified by the client instrumentation.string
directionThe direction of flow of bytes or operations.stringread, write
file_typeThe type of file being monitored.string
logical_filenameThe logical filename of the file being monitored.string
network.peer.addressIP address of the peer client.string
network.peer.portTCP port used by the peer client.int
typeThe page operation types.stringread, write
performance_counter.object_nameCategory to which this counter belongsstring
physical_filenameThe physical filename of the file being monitored.string
replica.directionThe direction of flow of bytes for replica.stringtransmit, receive
server.addressThe network address of the server hosting the database.string
server.portThe port number on which the server is listening.int
sqlserver.blocking.start_timeTimestamp of when the current blocking wait began (ISO 8601 format).string
sqlserver.blocking_session_idSession ID that is blocking the current session. 0 if none.int
sqlserver.commandSQL command type being executed.string
sqlserver.context_infoContext information for the session, represented as a hexadecimal string.string
sqlserver.cpu_timeCPU time consumed by the query, in seconds.double
sqlserver.deadlock_priorityDeadlock priority value for the session.int
sqlserver.estimated_completion_timeEstimated time remaining for the request to complete, in seconds.double
sqlserver.execution_countNumber of times that the plan has been executed since it was last compiled, reported in delta value.int
sqlserver.lock_timeoutLock timeout value in seconds.double
sqlserver.logical_readsNumber of logical reads (data read from cache/memory).int
sqlserver.open_transaction_countNumber of transactions currently open in the session.int
sqlserver.percent_completePercentage of work completed.double
sqlserver.procedure_execution_countNumber of times that the procedure has been executed since it was last compiled, reported in delta value.int
sqlserver.procedure_idThe SQL Server ID of the stored procedure, if anystring
sqlserver.procedure_nameThe name of the stored procedure, if anystring
sqlserver.query_hashBinary hash value calculated on the query and used to identify queries with similar logic, reported in the HEX format.string
sqlserver.query_planThe query execution plan used by the SQL Server.string
sqlserver.query_plan_hashBinary hash value calculated on the query execution plan and used to identify similar query execution plans, reported in the HEX format.string
sqlserver.query_startTimestamp of when the SQL query started (ISO 8601 format).string
sqlserver.readsNumber of physical reads performed by the query.int
sqlserver.request_statusStatus of the request (e.g., running, suspended).string
sqlserver.row_countNumber of rows affected or returned by the query.int
sqlserver.session_idID of the SQL Server session.int
sqlserver.session_statusStatus of the session (e.g., running, sleeping).string
sqlserver.total_elapsed_timeTotal elapsed time for completed executions of this plan, reported in delta seconds.double
sqlserver.total_grant_kbThe total amount of reserved memory grant in KB this plan received since it was compiled, reported in delta value.int
sqlserver.total_logical_readsTotal number of logical reads performed by executions of this plan since it was compiled, reported in delta value.int
sqlserver.total_logical_writesTotal number of logical writes performed by executions of this plan since it was compiled, reported in delta value.int
sqlserver.total_physical_readsTotal number of physical reads performed by executions of this plan since it was compiled, reported in delta value.int
sqlserver.total_rowsTotal number of rows returned by the query, reported in delta value.int
sqlserver.total_worker_timeTotal amount of CPU time that was consumed by executions of this plan since it was compiled, reported in delta seconds.double
sqlserver.transaction_idUnique ID of the active transaction.int
sqlserver.transaction_isolation_levelTransaction isolation level used in the session. Represented as numeric constant.int
sqlserver.wait.resource.idSQL Server identifier for the locked or waited-on resource, if available.string
sqlserver.wait.resource.typeSQL Server type of the locked or waited-on resource, if available.string
sqlserver.wait_resourceThe resource for which the session is waiting.string
sqlserver.wait_timeDuration in seconds the request has been waiting.double
sqlserver.wait_typeType of wait encountered by the request. Empty if none.string
sqlserver.writesNumber of writes performed by the query.int
table.stateThe state of the table.stringactive, inactive
table.statusThe status of the table.stringtemporary, permanent
tempdb.stateThe status of the tempdb space usage.stringfree, used
user.nameLogin name associated with the SQL Server session.string
wait.categoryCategory of the reason for a wait.string
wait.typeType of the wait, view WaitTypes documentation for more information.string

Resource Attributes

Attribute NameDescriptionTypeEnabled
host.nameThe host name of SQL Serverstring
server.addressName of the database host.string
server.portServer port number.int
service.instance.idA unique identifier of the SQL Server instance in the format host:port. This resource attribute is only available when the receiver is configured to directly connect to SQL Server.string
sqlserver.computer.nameThe name of the SQL Server instance being monitored.string
sqlserver.database.nameThe name of the SQL Server database.string
sqlserver.instance.nameThe name of the SQL Server instance being monitored.string

Configuration

Example Configuration

sqlserver:
  collection_interval: 10s

sqlserver/named:
  collection_interval: 10s
  computer_name: CustomServer
  instance_name: CustomInstance
  resource_attributes:
    sqlserver.computer.name:
      enabled: true
    sqlserver.instance.name:
      enabled: true
    server.port:
      enabled: true
    server.address:
      enabled: true
    service.instance.id:
      enabled: false
  top_query_collection:
    lookback_time: 60s
    max_query_sample_count: 1000
    top_query_count: 200
    collection_interval: 80s
  query_sample_collection:
    max_rows_per_query: 1450
  events:
    db.server.query_sample:
      enabled: true
    db.server.top_query:
      enabled: true

Last generated: 2026-04-20