Skip to content

Add database link to span context(#732) #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public void recycle(CharBuffer object) {
*/
@Nullable
private String user;

/**
* DB Link for connections between 2 databases
*/
@Nullable
private String dbLink;

/**
* Database instance name
Expand Down Expand Up @@ -176,13 +182,31 @@ public Db withUser(@Nullable String user) {
this.user = user;
return this;
}


/**
* DB Link for connections between 2 databases
*/
@Nullable
public String getDbLink() {
return dbLink;
}

/**
* DB Link for connections between 2 databases
*/
public Db withDbLink(@Nullable String dbLink) {
this.dbLink = dbLink;
return this;
}

@Override
public void resetState() {
instance = null;
statement = null;
type = null;
user = null;
dbLink = null;
if (statementBuffer != null) {
charBufferPool.recycle(statementBuffer);
}
Expand All @@ -194,6 +218,7 @@ public boolean hasContent() {
statement != null ||
type != null ||
user != null ||
dbLink != null ||
statementBuffer != null;
}

Expand All @@ -202,5 +227,6 @@ public void copyFrom(Db other) {
statement = other.statement;
type = other.type;
user = other.user;
dbLink = other.dbLink;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ private void serializeDbContext(final Db db) {
}
}
writeField("type", db.getType());
writeField("link", db.getDbLink());
writeLastField("user", db.getUser());
jw.writeByte(OBJECT_END);
jw.writeByte(COMMA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
"user": {
"type": ["string", "null"],
"description": "Username for accessing database"
},
"link": {
"type": ["string", "null"],
"description": "DB Link for connections between 2 databases"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public static List<Span> getSpans(Transaction t) {
.withInstance("customers")
.withStatement("SELECT * FROM product_types WHERE user_id=?")
.withType("sql")
.withUser("readonly_user");
.withUser("readonly_user")
.withDbLink("DB_LINK");
span.addLabel("monitored_by", "ACME");
span.addLabel("framework", "some-framework");
spans.add(span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ private void validateDbSpanSchema(JsonNode serializedSpans, boolean shouldContai
assertThat(db.get("statement").textValue()).isEqualTo("SELECT * FROM product_types WHERE user_id=?");
assertThat(db.get("type").textValue()).isEqualTo("sql");
assertThat(db.get("user").textValue()).isEqualTo("readonly_user");
assertThat(db.get("link").textValue()).isEqualTo("DB_LINK");
JsonNode tags = context.get("tags");
if (shouldContainTags) {
assertThat(tags).isNotNull();
Expand Down