Skip to content

Commit

Permalink
moved correlation id to the body of the test (#127)
Browse files Browse the repository at this point in the history
* moved correlation id to the body of the test
* better variable name
  • Loading branch information
ypopovych authored Aug 22, 2024
1 parent 177ff84 commit 7ee1c88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ class IntelligentTestRunner {
}

func start() {
if itrFolder != nil {
if itrFolder == nil {
createITRFolder()
} else {
// Previous commit folder exists, load from file
Log.debug("Skippable tests loaded from disk")
loadSkippableTestsFromDisk()

} else {
createITRFolder()
}
if _skippableTests == nil {
getSkippableTests(repository: DDTestMonitor.env.git.repositoryURL)
saveSkippableTestsToDisk()
} else {
Log.debug("Skippable tests loaded from disk")
}
}

Expand All @@ -54,7 +56,8 @@ class IntelligentTestRunner {
}

private func createITRFolder() {
itrFolder = try? DDTestMonitor.commitFolder?.createSubdirectory(path: itrCachePath)
itrFolder = try? DDTestMonitor.commitFolder?
.createSubdirectory(path: itrCachePath)
.createSubdirectory(path: DDTestMonitor.env.environment +
String(configurations.stableHash) +
String(DDTestMonitor.config.customConfigurations.stableHash))
Expand All @@ -66,7 +69,7 @@ class IntelligentTestRunner {
{
_skippableTests = skippableTests
}
Log.debug("Skippable Tests: \(_skippableTests.map {"\($0)"} ?? "nil")")
Log.debug("Load Skippable Tests: \(_skippableTests.map {"\($0)"} ?? "nil")")
}

private func saveSkippableTestsToDisk() {
Expand Down
14 changes: 12 additions & 2 deletions Sources/EventsExporter/Spans/SpanEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ internal struct DDSpan: Encodable {
let sessionID: UInt64?
let moduleID: UInt64?
let suiteID: UInt64?
let itrCorrelationId: String?

// MARK: - Meta

Expand All @@ -77,7 +78,9 @@ internal struct DDSpan: Encodable {
var tags: [String: AttributeValue]

static let filteredTagKeys: Set<String> = [
"error.message", "error.type", "error.stack", "test_module_id", "test_suite_id"
"error.message", "error.type", "error.stack",
"test_module_id", "test_suite_id", "test_session_id",
"itr_correlation_id"
]

func encode(to encoder: Encoder) throws {
Expand Down Expand Up @@ -121,16 +124,18 @@ internal struct DDSpan: Encodable {
self.sessionID = UInt64(spanData.attributes["test_session_id"]?.description ?? "0", radix: 16) ?? 0
self.moduleID = UInt64(spanData.attributes["test_module_id"]?.description ?? "0", radix: 16) ?? 0
self.suiteID = UInt64(spanData.attributes["test_suite_id"]?.description ?? "0", radix: 16) ?? 0
self.itrCorrelationId = spanData.attributes["itr_correlation_id"]?.description
} else {
self.sessionID = nil
self.moduleID = nil
self.suiteID = nil
self.itrCorrelationId = nil
}

self.applicationVersion = applicationVersion
self.tags = spanData.attributes.filter {
!DDSpan.filteredTagKeys.contains($0.key)
}.mapValues { $0 }
}
}
}

Expand All @@ -156,6 +161,7 @@ internal struct SpanEncoder {
case errorMessage = "error.message"
case errorType = "error.type"
case errorStack = "error.stack"
case itrCorrelationId = "itr_correlation_id"

// MARK: - Metrics

Expand Down Expand Up @@ -204,6 +210,10 @@ internal struct SpanEncoder {

try container.encode(span.startTime, forKey: .start)
try container.encode(span.duration, forKey: .duration)

if let correlationId = span.itrCorrelationId {
try container.encode(correlationId, forKey: .itrCorrelationId)
}

var meta = container.nestedContainer(keyedBy: DynamicCodingKey.self, forKey: .meta)
var metrics = container.nestedContainer(keyedBy: DynamicCodingKey.self, forKey: .metrics)
Expand Down

0 comments on commit 7ee1c88

Please sign in to comment.