Skip to content

Commit 0ba17ad

Browse files
author
Ignacio Bonafonte
authored
Merge pull request #421 from open-telemetry/log-example
2 parents 37b52e2 + e35e33b commit 0ba17ad

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Examples/Logs Sample/main.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Copyright The OpenTelemetry Authors
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
6+
import Foundation
7+
import OpenTelemetryApi
8+
import OpenTelemetrySdk
9+
import OpenTelemetryProtocolExporterGrpc
10+
import Logging
11+
import GRPC
12+
import NIO
13+
14+
15+
func configure() {
16+
let configuration = ClientConnection.Configuration.default(
17+
target: .hostAndPort("localhost", 4317),
18+
eventLoopGroup: MultiThreadedEventLoopGroup(numberOfThreads: 1))
19+
20+
21+
OtlpLogExporter(channel: ClientConnection(configuration: configuration))
22+
23+
OpenTelemetry.registerLoggerProvider(loggerProvider: LoggerProviderBuilder().with(processors: [
24+
BatchLogRecordProcessor(logRecordExporter:OtlpLogExporter(channel: ClientConnection(configuration: configuration)))]).build())
25+
26+
}
27+
28+
configure()
29+
30+
let eventProvider = OpenTelemetry.instance.loggerProvider.loggerBuilder(instrumentationScopeName: "myScope").setEventDomain("device").build()
31+
32+

[email protected]

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ let package = Package(
212212
path: "Examples/Datadog Sample",
213213
exclude: ["README.md"]
214214
),
215+
.executableTarget(
216+
name: "LogsSample",
217+
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporterGrpc", .product(name: "GRPC", package: "grpc-swift")],
218+
path: "Examples/Logs Sample"),
215219
.executableTarget(
216220
name: "NetworkSample",
217221
dependencies: ["URLSessionInstrumentation", "StdoutExporter"],

0 commit comments

Comments
 (0)