---
title: "Logging with OpenTelemetry"
description: "Send the log of the LumiScan Annotation Web server to Loki, an OpenTelemetry Collector or Grafana Alloy over OTLP: configuration, environment variables and the fields of every log record."
product: "LumiScan Annotation Web"
component: "lumiscan-annotation-web"
version: "2.7.0"
display_version: "2.7.0.0"
latest_version: true
language: "en"
url: "https://docs.hdvisionsystems.com/en/lumiscan-annotation-web/logging-with-opentelemetry.html"
---

# Logging with OpenTelemetry – LumiScan Annotation Web

From version 2.6 the server can send every line of its log as an OpenTelemetry log record to a collector: Grafana Loki (version 3, native OTLP endpoint), an OpenTelemetry Collector or Grafana Alloy. The console and the log files (`log_dir`) stay as they are. Logs of several servers and other LumiScan software can then be searched in one place.

The server sends OTLP over HTTP with JSON. Sending never holds the server up: the records wait in a queue and go out in batches. If the collector cannot be reached, the server keeps running, keeps the records and tries again.

## Switching it on

Add a section `telemetry` to the [configuration](https://docs.hdvisionsystems.com/en/lumiscan-annotation-web/configuration.html) and restart the server:

```json
  "telemetry": {
    "endpoint": "http://monitoring01:3100/otlp",
    "environment": "production"
  },
```

The server posts the records to `<endpoint>/v1/logs`. Typical endpoints:

- Loki 3: `http://<loki-server>:3100/otlp`
- OpenTelemetry Collector or Grafana Alloy (OTLP/HTTP receiver): `http://<collector>:4318`

At the start the log names the address and the identity of this start, for example:

```
OpenTelemetry: log records go to http://monitoring01:3100/otlp/v1/logs (service.name lumiscan-annotation-server, service.instance.id 3f2c9e1a-...)
```

Without a `telemetry` section (and without the environment variables below) nothing is sent.

## Keys

| Key | Meaning |
| --- | --- |
| `enabled` | `false` switches sending off and keeps the section. Default: `true` when the section is there. |
| `endpoint` | Base address of the collector, `http://` or `https://`. `/v1/logs` is appended. |
| `logs_endpoint` | Optional: the complete address of the logs endpoint, used as it is (instead of `endpoint`). |
| `headers` | Optional: further HTTP headers, for example `{ "X-Scope-OrgID": "lumiscan" }`. |
| `headers_file` | Optional: a file with headers that hold secrets (for example `Authorization=Basic …` or `Authorization=Bearer …`), one `Name=value` per line. Keep it readable for the service account only. Header values never appear in the log. |
| `service_name` | `service.name` of the records. Default: `lumiscan-annotation-server`. Give each server its own name only if they must be told apart by more than `host.name`. |
| `environment` | Optional: `deployment.environment.name`, for example `production` or `test`. |
| `resource` | Optional: further resource attributes, for example `{ "site": "heidelberg" }` (strings, numbers or `true`/`false`). |
| `level` | The lowest level sent: `trace`, `debug`, `info` (default), `warn`, `error` or `critical`. It cannot send more than the log itself contains (`info` unless `SPDLOG_LEVEL` says otherwise). |
| `timeout_ms` | Time limit for one request, in milliseconds. Default 10000. |
| `batch_size` | Records per request at most. Default 512. |
| `flush_interval_ms` | A batch goes out at the latest after this time, in milliseconds. Default 2000. |
| `queue_max` | Records kept while the collector cannot be reached. Default 20000; further records are not sent (the log file has them). |
| `ca_file` | Optional: CA certificates (PEM) for an `https://` endpoint signed by your company’s CA. |
| `tls_verify` | `false` switches the certificate check off (for tests only). Default `true`. |
| `personal_data` | What happens to user names, computer addresses and e-mail addresses in the records: `pseudonymize` (default; `omit` when `log_personal_data` is `omit`), `keep` or `omit`. See [Personal data in the log](https://docs.hdvisionsystems.com/en/lumiscan-annotation-web/configuration.html#personal-data). |

## Environment variables

The server also reads the standard variables of the OpenTelemetry SDKs. They win over the configuration file, so an endpoint can be set without changing the file. If only the variables are set, sending is on.

| Variable | Meaning |
| --- | --- |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | Like `endpoint`. |
| `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` | Like `logs_endpoint`. |
| `OTEL_EXPORTER_OTLP_HEADERS`, `OTEL_EXPORTER_OTLP_LOGS_HEADERS` | Headers as `name=value,name=value`; `%20` stands for a space. |
| `OTEL_EXPORTER_OTLP_TIMEOUT`, `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT` | Like `timeout_ms`. |
| `OTEL_EXPORTER_OTLP_CERTIFICATE`, `OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE` | Like `ca_file`. |
| `OTEL_EXPORTER_OTLP_PROTOCOL`, `OTEL_EXPORTER_OTLP_LOGS_PROTOCOL` | Only `http/json` is supported; other values stop the start with a message. |
| `OTEL_SERVICE_NAME` | Like `service_name`. |
| `OTEL_RESOURCE_ATTRIBUTES` | Resource attributes as `key=value,key=value`, for example `deployment.environment.name=test`. |
| `OTEL_SDK_DISABLED=true`, `OTEL_LOGS_EXPORTER=none` | Nothing is sent, whatever the file says. |

For a service, set the variables where the service starts: on Linux an `Environment=` line in the systemd unit, on Windows as system environment variables. Then restart the service.

## What a log record contains

The field names follow the OpenTelemetry log data model and semantic conventions (schema 1.34.0), as the LumiScan log aggregation prescribes them for all LumiScan software.

| OpenTelemetry field | Name in JSON lines | Value |
| --- | --- | --- |
| Timestamp | `timestamp` | When the line was written. |
| SeverityNumber | `severity_number` | `1` trace, `5` debug, `9` info, `13` warning, `17` error, `21` critical. |
| SeverityText | `severity_text` | `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`. |
| Body | `body` | The message, as in the log file (with personal data handled as `personal_data` says). |
| InstrumentationScope | `scope.name` | `annotation`, the server’s logger; its version is the server version. |
| EventName | `event.name` | The audit event, see [Audit events](https://docs.hdvisionsystems.com/en/lumiscan-annotation-web/logging-with-opentelemetry.html#audit-events); also sent as the attribute `event.name`. |

Resource attributes (the same in every record of a server start):

| Attribute | Value |
| --- | --- |
| `service.name` | `lumiscan-annotation-server` or `service_name`. |
| `service.version` | The server version, for example `2.6.0.0`. |
| `service.namespace` | `lumiscan`. |
| `service.instance.id` | A new random ID at every start: separates the runs of one server. |
| `host.name` | The computer’s host name. |
| `host.id` | The machine ID of the operating system (Linux `/etc/machine-id`, Windows `MachineGuid`). |
| `host.arch` | `amd64` or `arm64`. |
| `os.type` | `windows` or `linux`. |
| `deployment.environment.name` | `environment`, when set. |

Log attributes:

| Attribute | Value |
| --- | --- |
| `thread.id` | The thread that wrote the line. |
| `event.name` | The audit event, see [Audit events](https://docs.hdvisionsystems.com/en/lumiscan-annotation-web/logging-with-opentelemetry.html#audit-events). |
| `exception.type`, `exception.message` | On the line `Fatal: …` when the server stops because of an error. |
| `code.file.path`, `code.line.number`, `code.function.name` | Where in the program the line was written, when the server knows it. |

### Audit events {#audit-events}

| Event | When |
| --- | --- |
| `lumiscan.app.started` | The server listens and takes requests (`Listening on …`). |
| `lumiscan.app.stopped` | The server has stopped (`Stopped`). |
| `lumiscan.licence.found` | The licence is available: at the start, and when it comes back. |
| `lumiscan.licence.missing` | The licence is not available: at the start, and when it goes away. |
| `lumiscan.session.opened` | A user signed in (local account, LDAP or single sign-on). |
| `lumiscan.session.refused` | A sign-in failed. |

## Searching the log in Grafana (Loki)

Loki turns the dots of attribute names into underscores. Examples in LogQL:

```none
{service_name="lumiscan-annotation-server"}
{service_name="lumiscan-annotation-server"} | severity_text="ERROR"
{service_name="lumiscan-annotation-server"} | event_name="lumiscan.session.refused"
{service_name="lumiscan-annotation-server", host_name="annotation01"} | service_instance_id="3f2c9e1a-..."
{service_name="lumiscan-annotation-server"} |= "user-3f9a1c2b7d"
```

The last line finds the lines of one user in pseudonymized records; `--pseudonym` gives the pseudonym (see [Personal data in the log](https://docs.hdvisionsystems.com/en/lumiscan-annotation-web/configuration.html#personal-data)).

Loki 3 keeps the attributes as structured metadata (schema v13, `allow_structured_metadata`). Keep the index labels coarse, as the log aggregation asks: by default Loki also makes `service.instance.id` a label, which starts a new stream at every restart. In the Loki configuration:

```yaml
limits_config:
  allow_structured_metadata: true
  otlp_config:
    resource_attributes:
      ignore_defaults: true
      attributes_config:
        - action: index_label
          attributes: [service.name, service.namespace, service.version, host.name, deployment.environment.name]
```

## When the collector cannot be reached

- The server keeps running. Records wait in the queue (up to `queue_max`) and are sent again after 1 s, 2 s, 4 s … up to 1 minute between tries.
- The console and the log file say so at once and then at most every 10 minutes (`OpenTelemetry: cannot deliver log records to …`), and again when the records arrive (`… reach … again`).
- A request the collector refuses (for example HTTP 400) is not repeated; the log file says so.
- When the server stops, it sends what is still queued for up to 5 seconds.
- The log file always has every line.

## Data protection

By default the records carry pseudonyms instead of user names, computer addresses and e-mail addresses (`personal_data`, see [Personal data in the log](https://docs.hdvisionsystems.com/en/lumiscan-annotation-web/configuration.html#personal-data)), as the LumiScan log aggregation asks for logs that leave the server. With `keep` they contain the same text as the log file. Give access to the collector only to those who may read the server log. Passwords, tokens, images and annotation contents never appear in the log.
