opentelemetry-swift
opentelemetry-swift copied to clipboard
Instrument Framework
Hey,
I'm currently checking out the OpenTelemetry Swift agent. I'm running it without any issues on a test iOS application, but now I'm trying to instrument a dummy library to get some spans out of it. I created a new framework, included the API only (as mentioned in the README):
Framework Code
import Foundation
import OpenTelemetryApi
public class Test {
public static func doSomething() {
let tracer = OpenTelemetry.instance.tracerProvider.get(instrumentationName: "OtelInstrLib", instrumentationVersion: "0.0.1")
let span = tracer.spanBuilder(spanName: "doSomethingSpan").setSpanKind(spanKind: .client).setActive(true).startSpan()
Thread.sleep(forTimeInterval: 0.1)
span.end()
}
}
I'm importing that in my sample iOS Application and expecting to see the span being generated / logged with the StdoutExporter, but that doesn't happen.
iOS App Code
import UIKit
import OpenTelemetrySdk
import StdoutExporter
import OtelInstrLib
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
internal func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let instrumentationLibraryName = "OTel-Swift-Sample-osia"
let instrumentationLibraryVersion = "semver:0.1.0"
var tracer: TracerSdk
tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: instrumentationLibraryName, instrumentationVersion: instrumentationLibraryVersion) as! TracerSdk
let stdoutExporter = StdoutExporter(isDebug: true)
OpenTelemetrySDK.instance.tracerProvider.addSpanProcessor(spanProcessor)
let span = tracer.spanBuilder(spanName: "SimpleSpan").setSpanKind(spanKind: .client).startSpan()
Thread.sleep(forTimeInterval: 0.1)
span.end()
// instrumented library
Test.doSomething()
// app code
// ...
return true
}
Stdout
objc[99521]: Class _TtC16OpenTelemetryApi14DefaultBaggage is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b04830) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1ee20). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi21DefaultBaggageBuilder is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b048e0) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1eed0). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi21DefaultBaggageManager is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b04a00) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1eff0). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi29DefaultBaggageManagerProvider is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b04aa0) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1f090). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi12EmptyBaggage is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b04b38) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1f128). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi19EmptyBaggageBuilder is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b04bd8) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1f1c8). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi23JaegerBaggagePropagator is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b04cc0) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1f2b0). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi23ZipkinBaggagePropagator is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b04dd0) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1f3c0). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi22ActivityContextManager is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b05080) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1f670). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtCC16OpenTelemetryApi22ActivityContextManager12ScopeElement is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b05178) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1f768). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi20DefaultMeterProvider is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b05318) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1f908). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi8LabelSet is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b05408) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1f9f8). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi13DefaultTracer is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b055d8) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1fbc8). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi21DefaultTracerProvider is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b05670) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1fc60). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi14PropagatedSpan is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b05718) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1fd08). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi21PropagatedSpanBuilder is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b05870) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1fe60). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi12B3Propagator is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b059b0) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d1ffa0). One of the two will be used. Which one is undefined.
objc[99521]: Class _TtC16OpenTelemetryApi16JaegerPropagator is implemented in both /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/Frameworks/OtelInstrLib.framework/OtelInstrLib (0x105b05ab0) and /Users/**HIDDEN**/Library/Developer/CoreSimulator/Devices/6C5813E2-E386-437F-B128-910F7116F16C/data/Containers/Bundle/Application/5D19C648-2C77-4AA0-BA14-38E96E480750/osia.app/osia (0x103d200a0). One of the two will be used. Which one is undefined.
__________________
Span SimpleSpan:
TraceId: 64aca828251d9b8060612f2ad9db16e1
SpanId: a3bb1bf0a4ffa414
Span kind: client
TraceFlags: TraceFlags{sampled=true}
TraceState: TraceState(entries: [])
ParentSpanId: 0000000000000000
Start: 1642603691149065984
Duration: 100318074 nanoseconds
Attributes: [:]
------------------
2022-01-19 15:48:12.637216+0100 osia[99521:1613227] [boringssl] boringssl_metrics_log_metric_block_invoke(151) Failed to log metrics
This builds fine, it logs the span generated in the app, but not in the framework. It seems to always fall back to the noop implementation of the API in the framework.
- Is is expected to get warnings about the duplicate implementation?
- Am I doing wrong / missing something here?
Maybe someone has tried that before and give me a hint.
Thanks!
The issue comes from the opentelemetry library being linked in both the framework and the application, that is what the warning is telling. As you have it linked twice, both the framework and the app have different copies of the library so you have a different Opentelemetry instance in each one.
This is a usual problem with SPM, that it defaults to linking statically always. There are several ways you can solve it, the easiest being linking Opentelemetry only on the framework, and linking the framework with your app (you will still be able to import Opentelemetry in the app). If you have some complex dependency setting you may want to use SPM for the project setup so it takes care of the dependency, or create yourself a dynamic library to export the opentelemetry stuff or some other approach, but you must be sure that Opentelemetry is only linked once.
Let us know if it solves it for you.
So the double linking problem is the root cause? Didn't notice that SPM links it statically, thanks. Will look into that.
But apart from that, isn't one idea of OpenTelemetry that libraries can also provide telemetry data which can be gathered on demand by the main application? If linking has to be taken into account in such detail during the library and app development, it doesn't seem to work out in swift, right?
Sounds like the issue got resolved. Closing for now. Please reopen if the issue still persists.