Skip to content

Commit 1599d5f

Browse files
author
Ignacio Bonafonte
authored
Merge pull request #172 from bryce-b/resource-merging-fix
The Resource created here should be overwritten with new data
2 parents 35ac7ac + 5fda28c commit 1599d5f

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

Sources/Instrumentation/SDKResourceExtension/DataSource/TelemetryDataSource.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ public class TelemetryDataSource: ITelemetryDataSource {
2121
}
2222

2323
public var name: String {
24-
#if os(tvOS)
25-
return "tvOS"
26-
#elseif os(watchOS)
27-
return "watchOS"
28-
#elseif os(macOS)
29-
return "macOS"
30-
#else
31-
return "iOS"
32-
#endif
24+
"opentelemetry"
3325
}
3426

3527
public var version: String? {

Sources/Instrumentation/SDKResourceExtension/DefaultResources.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class DefaultResources {
3131
let mirror = Mirror(reflecting: self)
3232
for children in mirror.children {
3333
if let provider = children.value as? ResourceProvider {
34-
resource.merge(other: provider.create())
34+
resource = provider.create().merging(other: resource)
3535
}
3636
}
3737
return resource
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2021, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
import Foundation
16+
17+
import OpenTelemetryApi
18+
import OpenTelemetrySdk
19+
@testable import ResourceExtension
20+
import XCTest
21+
22+
class ResourcePropogationTests : XCTestCase {
23+
func testPropogation() {
24+
let defaultResource = Resource()
25+
let appProvider = ApplicationResourceProvider(source: ApplicationDataSource())
26+
let telemetryProvider = TelemetryResourceProvider(source: TelemetryDataSource())
27+
let resultResource = DefaultResources().get()
28+
29+
let defaultValue = defaultResource.attributes[ResourceAttributes.serviceName.rawValue]?.description
30+
let resultValue = resultResource.attributes[ResourceAttributes.serviceName.rawValue]?.description
31+
let applicationName = appProvider.attributes[ResourceAttributes.serviceName.rawValue]?.description
32+
33+
34+
XCTAssertNotNil(defaultValue)
35+
XCTAssertNotNil(resultValue)
36+
XCTAssertNotNil(applicationName)
37+
XCTAssertEqual(resultValue, applicationName)
38+
XCTAssertNotEqual(resultValue, defaultValue)
39+
40+
41+
}
42+
}

0 commit comments

Comments
 (0)