You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/product/drains/otlp-guides/nginx.mdx
+69-18Lines changed: 69 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,12 +37,54 @@ ___OTLP_LOGS_URL___
37
37
x-sentry-auth: sentry sentry_key=___PUBLIC_KEY___
38
38
```
39
39
40
-
## Step 3: Configure Nginx Logging (Optional)
40
+
## Step 3: Configure Nginx Logging
41
41
42
-
Nginx logs are stored by default at `/var/log/nginx/access.log`. For better log parsing, you can configure Nginx to output logs in JSON format.
42
+
Nginx logs are stored by default at `/var/log/nginx/access.log`. For better observability, configure Nginx to output structured JSON logs with trace context fields. This allows your Nginx logs to be correlated with distributed traces in Sentry.
43
+
44
+
### JSON Logging with Trace Context (Recommended)
45
+
46
+
To correlate Nginx logs with traces, you need to include trace context fields in your log format. This requires the [NGINX OpenTelemetry module](https://github.com/open-telemetry/opentelemetry-cpp-contrib/tree/main/instrumentation/nginx) to be installed, which provides the `$otel_trace_id`, `$otel_span_id`, and `$otel_trace_flags` variables.
43
47
44
48
Add the following to your Nginx configuration (typically `/etc/nginx/nginx.conf`):
The trace context fields enable Sentry to link your Nginx access logs directly to the corresponding traces, giving you full visibility into request flows.
83
+
84
+
### Basic JSON Logging (Without Trace Context)
85
+
86
+
If you don't have the OpenTelemetry module installed, you can still use structured JSON logging:
87
+
46
88
```nginx {filename:nginx.conf}
47
89
http {
48
90
log_format json_combined escape=json
@@ -77,18 +119,36 @@ Create a configuration file with the File Log Receiver and the OTLP HTTP exporte
77
119
78
120
For additional configuration options, see the [File Log Receiver Documentation](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/filelogreceiver).
79
121
80
-
### Basic Configuration
122
+
### Configuration with Trace Context (Recommended)
81
123
82
-
This configuration collects Nginx access and error logs:
124
+
If you configured Nginx with the OpenTelemetry module and JSON logging with trace context fields, use this configuration to parse the logs and extract trace correlation:
83
125
84
126
```yaml {filename:config.yaml}
85
127
receivers:
86
128
filelog:
87
129
include:
88
130
- /var/log/nginx/access.log
131
+
attributes:
132
+
service.name: nginx
133
+
operators:
134
+
- type: json_parser
135
+
timestamp:
136
+
parse_from: attributes.time_local
137
+
layout: "%d/%b/%Y:%H:%M:%S %z"
138
+
- type: trace_parser
139
+
trace_id:
140
+
parse_from: attributes.trace_id
141
+
span_id:
142
+
parse_from: attributes.span_id
143
+
trace_flags:
144
+
parse_from: attributes.trace_flags
145
+
146
+
filelog/error:
147
+
include:
89
148
- /var/log/nginx/error.log
90
149
attributes:
91
150
service.name: nginx
151
+
log.type: error
92
152
93
153
processors:
94
154
batch:
@@ -109,35 +169,27 @@ service:
109
169
logs:
110
170
receivers:
111
171
- filelog
172
+
- filelog/error
112
173
processors:
113
174
- batch
114
175
exporters:
115
176
- otlphttp/sentry
116
177
```
117
178
118
-
### Configuration with JSON Parsing
179
+
The `trace_parser` operator extracts the trace ID, span ID, and trace flags from the parsed JSON attributes and sets them on the log record. This enables Sentry to correlate these logs with the corresponding traces.
180
+
181
+
### Basic Configuration
119
182
120
-
If you configured Nginx to output JSON logs, you can parse them for structured log data:
183
+
This configuration collects Nginx access and error logs:
0 commit comments