Skip to content

Commit 6b7a63d

Browse files
authored
Merge pull request #149 from nblumhardt/env-var-readme
README updates for v4
2 parents 8f8612e + 1f7a15b commit 6b7a63d

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

README.md

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ examples below.
3838

3939
## Configuration
4040

41-
This sink supports two configuration styles: inline and options. The
42-
inline configuration looks like:
41+
This sink supports two configuration styles: inline and options.
42+
Inline configuration is appropriate for simple, local logging
43+
setups, and looks like:
4344

4445
```csharp
4546
Log.Logger = new LoggerConfiguration()
@@ -49,10 +50,7 @@ Log.Logger = new LoggerConfiguration()
4950
.CreateLogger();
5051
```
5152

52-
This configuration is appropriate only for simple, local logging
53-
setups.
54-
55-
More complicated use cases will need to use the options
53+
More complicated use cases need to use options-style
5654
configuration, which looks like:
5755

5856
```csharp
@@ -63,35 +61,28 @@ Log.Logger = new LoggerConfiguration()
6361
options.Protocol = OtlpProtocol.HttpProtobuf;
6462
})
6563
.CreateLogger();
66-
6764
```
6865

6966
This supports the sink's full set of configuration options. See the
7067
`OpenTelemetrySinkOptions.cs` file for the full set of options.
71-
Some of the more imporant parameters are discussed in the following
68+
Some of the more important parameters are discussed in the following
7269
sections.
7370

7471
### Endpoint and protocol
7572

76-
The default endpoint is `http://localhost:4317`, which will send
77-
logs to an OpenTelemetry collector running on the same machine over
78-
the gRPC protocol. This is appropriate for testing or for using a
79-
local OpenTelemetry collector as a proxy for a downstream logging service.
73+
The default endpoint and protocol are `http://localhost:4317` and `OtlpProtocol.Grpc`.
8074

81-
In most production scenarios, you will want to set an endpoint. To do so,
82-
add the `endpoint` argument to the `WriteTo.OpenTelemetry()` call.
75+
In most production scenarios, you'll need to set an endpoint and protocol to suit your
76+
deployment environment. To do so, add the `endpoint` argument to the `WriteTo.OpenTelemetry()` call.
8377

84-
You may also want to set the protocol explicitly. The supported values
78+
You may also want to set the protocol. The supported values
8579
are:
8680

8781
- `OtlpProtocol.Grpc`: Sends a protobuf representation of the
8882
OpenTelemetry Logs over a gRPC connection (the default).
8983
- `OtlpProtocol.HttpProtobuf`: Sends a protobuf representation of the
9084
OpenTelemetry Logs over an HTTP connection.
9185

92-
When the `OtlpProtocol.HttpProtobuf` option is specified, the endpoint
93-
URL **must** include the full path, for example `http://localhost:4318/v1/logs`.
94-
9586
### Resource attributes
9687

9788
OpenTelemetry logs may contain a "resource" that provides metadata concerning
@@ -126,6 +117,15 @@ Log.Logger = new LoggerConfiguration()
126117
.CreateLogger();
127118
```
128119

120+
### Environment variable overrides
121+
122+
The sink also recognizes a selection of the `OTEL_OTLP_EXPORTER_*` environment variables described in
123+
the [OpenTelemetry documentation](https://opentelemetry.io/docs/specs/otel/protocol/exporter/), and will
124+
override programmatic configuration with any environment variable values present at runtime.
125+
126+
To switch off this behavior, pass `ignoreEnvironment: true` to the `WriteTo.OpenTelemetry()` configuration
127+
methods.
128+
129129
## Serilog `LogEvent` to OpenTelemetry log record mapping
130130

131131
The following table provides the mapping between the Serilog log
@@ -165,6 +165,24 @@ Log.Logger = new LoggerConfiguration()
165165
The example shows the default value; `IncludedData.MessageTemplateMD5HashAttribute` can
166166
also be used to add the MD5 hash of the message template.
167167

168+
## Sending traces through the sink
169+
170+
Serilog `LogEvents` that carry a `SpanStartTimestamp` property of type `DateTime` will be
171+
recognized as spans by this sink, and sent using the appropriate OpenTelemetry endpoint
172+
and schema. The properties recognized by the sink match the ones emitted by
173+
[SerilogTracing](https://github.com/serilog-tracing/serilog-tracing).
174+
175+
In addition to the field mapping performed for log records, events that represent trace
176+
spans can carry the special properties listed below.
177+
178+
Serilog `LogEvent` | OpenTelemetry `Span` | Comments |
179+
---------------------------------|----------------------|----------------------------------------|
180+
`MessageTemplate` | `Name` | |
181+
`Properties["ParentSpanId"]` | `ParentSpanId` | Value must be of type `ActivitySpanId` |
182+
`Properties["SpanKind"]` | `Kind` | Value must be of type `ActivityKind` |
183+
`Properties["SpanStartTimestamp"]` | `StartTimeUnixNano` | Value must be of type `DateTime`; .NET provides 100-nanosecond precision |
184+
`Timestamp` | `EndTimeUnixNano` | .NET provides 100-nanosecond precision |
185+
168186
## Example
169187

170188
The `example/Example` subdirectory contains an example application that logs

0 commit comments

Comments
 (0)