-
Notifications
You must be signed in to change notification settings - Fork 886
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
998 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...r/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/MultiQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.incubator.semconv.db; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
class MultiQuery { | ||
private static final SqlStatementSanitizer sanitizer = SqlStatementSanitizer.create(true); | ||
|
||
private final String mainIdentifier; | ||
private final String operation; | ||
private final Set<String> statements; | ||
|
||
private MultiQuery(String mainIdentifier, String operation, Set<String> statements) { | ||
this.mainIdentifier = mainIdentifier; | ||
this.operation = operation; | ||
this.statements = statements; | ||
} | ||
|
||
static MultiQuery analyze( | ||
Collection<String> rawQueryTexts, boolean statementSanitizationEnabled) { | ||
UniqueValue uniqueMainIdentifier = new UniqueValue(); | ||
UniqueValue uniqueOperation = new UniqueValue(); | ||
Set<String> uniqueStatements = new LinkedHashSet<>(); | ||
for (String rawQueryText : rawQueryTexts) { | ||
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(rawQueryText); | ||
String mainIdentifier = sanitizedStatement.getMainIdentifier(); | ||
uniqueMainIdentifier.set(mainIdentifier); | ||
String operation = sanitizedStatement.getOperation(); | ||
uniqueOperation.set(operation); | ||
uniqueStatements.add( | ||
statementSanitizationEnabled ? sanitizedStatement.getFullStatement() : rawQueryText); | ||
} | ||
|
||
return new MultiQuery( | ||
uniqueMainIdentifier.getValue(), uniqueOperation.getValue(), uniqueStatements); | ||
} | ||
|
||
public String getMainIdentifier() { | ||
return mainIdentifier; | ||
} | ||
|
||
public String getOperation() { | ||
return operation; | ||
} | ||
|
||
public Set<String> getStatements() { | ||
return statements; | ||
} | ||
|
||
private static class UniqueValue { | ||
private String value; | ||
private boolean valid = true; | ||
|
||
void set(String value) { | ||
if (!valid) { | ||
return; | ||
} | ||
if (this.value == null) { | ||
this.value = value; | ||
} else if (!this.value.equals(value)) { | ||
valid = false; | ||
} | ||
} | ||
|
||
String getValue() { | ||
return valid ? value : null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...nstrumentation/api/incubator/semconv/db/internal/MultiQuerySqlClientAttributesGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.incubator.semconv.db.internal; | ||
|
||
import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlClientAttributesExtractor; | ||
import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlClientAttributesGetter; | ||
import java.util.Collection; | ||
|
||
/** | ||
* An extended version of {@link SqlClientAttributesGetter} for getting SQL database client | ||
* attributes for operations that run multiple distinct queries. | ||
* | ||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
* at any time. | ||
*/ | ||
public interface MultiQuerySqlClientAttributesGetter<REQUEST> | ||
extends SqlClientAttributesGetter<REQUEST> { | ||
|
||
/** | ||
* Get the raw SQL statements. The value returned by this method is later sanitized by the {@link | ||
* SqlClientAttributesExtractor} before being set as span attribute. | ||
*/ | ||
Collection<String> getRawQueryTexts(REQUEST request); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.