Skip to content

Commit 63628bf

Browse files
wolframhaussigeyalkoren
authored andcommitted
Add database link to span context(#732) (#735)
1 parent 076a95b commit 63628bf

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Db.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ public void recycle(CharBuffer object) {
8181
*/
8282
@Nullable
8383
private String user;
84+
85+
/**
86+
* DB Link for connections between 2 databases
87+
*/
88+
@Nullable
89+
private String dbLink;
8490

8591
/**
8692
* Database instance name
@@ -176,13 +182,31 @@ public Db withUser(@Nullable String user) {
176182
this.user = user;
177183
return this;
178184
}
185+
186+
187+
/**
188+
* DB Link for connections between 2 databases
189+
*/
190+
@Nullable
191+
public String getDbLink() {
192+
return dbLink;
193+
}
194+
195+
/**
196+
* DB Link for connections between 2 databases
197+
*/
198+
public Db withDbLink(@Nullable String dbLink) {
199+
this.dbLink = dbLink;
200+
return this;
201+
}
179202

180203
@Override
181204
public void resetState() {
182205
instance = null;
183206
statement = null;
184207
type = null;
185208
user = null;
209+
dbLink = null;
186210
if (statementBuffer != null) {
187211
charBufferPool.recycle(statementBuffer);
188212
}
@@ -194,6 +218,7 @@ public boolean hasContent() {
194218
statement != null ||
195219
type != null ||
196220
user != null ||
221+
dbLink != null ||
197222
statementBuffer != null;
198223
}
199224

@@ -202,5 +227,6 @@ public void copyFrom(Db other) {
202227
statement = other.statement;
203228
type = other.type;
204229
user = other.user;
230+
dbLink = other.dbLink;
205231
}
206232
}

apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ private void serializeDbContext(final Db db) {
730730
}
731731
}
732732
writeField("type", db.getType());
733+
writeField("link", db.getDbLink());
733734
writeLastField("user", db.getUser());
734735
jw.writeByte(OBJECT_END);
735736
jw.writeByte(COMMA);

apm-agent-core/src/main/resources/schema/transactions/span.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
"user": {
5656
"type": ["string", "null"],
5757
"description": "Username for accessing database"
58+
},
59+
"link": {
60+
"type": ["string", "null"],
61+
"description": "DB Link for connections between 2 databases"
5862
}
5963
}
6064
}

apm-agent-core/src/test/java/co/elastic/apm/agent/TransactionUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public static List<Span> getSpans(Transaction t) {
9393
.withInstance("customers")
9494
.withStatement("SELECT * FROM product_types WHERE user_id=?")
9595
.withType("sql")
96-
.withUser("readonly_user");
96+
.withUser("readonly_user")
97+
.withDbLink("DB_LINK");
9798
span.addLabel("monitored_by", "ACME");
9899
span.addLabel("framework", "some-framework");
99100
spans.add(span);

apm-agent-core/src/test/java/co/elastic/apm/agent/impl/payload/TransactionPayloadJsonSchemaTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ private void validateDbSpanSchema(JsonNode serializedSpans, boolean shouldContai
251251
assertThat(db.get("statement").textValue()).isEqualTo("SELECT * FROM product_types WHERE user_id=?");
252252
assertThat(db.get("type").textValue()).isEqualTo("sql");
253253
assertThat(db.get("user").textValue()).isEqualTo("readonly_user");
254+
assertThat(db.get("link").textValue()).isEqualTo("DB_LINK");
254255
JsonNode tags = context.get("tags");
255256
if (shouldContainTags) {
256257
assertThat(tags).isNotNull();

0 commit comments

Comments
 (0)