-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from GuanceCloud/jdbc-obfucation
jdbc.sql.obfuscation
- Loading branch information
Showing
5 changed files
with
140 additions
and
2 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
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
36 changes: 36 additions & 0 deletions
36
.../jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/DbSetArgs.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,36 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.jdbc.internal; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public final class DbSetArgs { | ||
private HashMap<Integer, String> args; | ||
|
||
public DbSetArgs(HashMap<Integer, String> map) { | ||
this.args = map; | ||
} | ||
|
||
public HashMap<Integer, String> getArgs() { | ||
return this.args; | ||
} | ||
|
||
public void setArgs(HashMap<Integer, String> args) { | ||
this.args = args; | ||
} | ||
|
||
public void setArg(Integer index, String arg) { | ||
this.args.put(index, arg); | ||
} | ||
|
||
public void resetArgs() { | ||
this.args = new HashMap<Integer, String>(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
.../library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JDBCAttributes.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,52 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.jdbc.internal; | ||
|
||
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.AttributesBuilder; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
@SuppressWarnings("UnusedTypeParameter") | ||
public final class JDBCAttributes<REQUEST, RESPONSE> implements AttributesExtractor<REQUEST, RESPONSE> { | ||
|
||
private DbSetArgs args; | ||
|
||
private JDBCAttributes(){} | ||
|
||
public static JDBCAttributes<DbRequest, Void> create(DbSetArgs args) { | ||
JDBCAttributes<DbRequest, Void> j = new JDBCAttributes<>(); | ||
j.setArgs(args); | ||
return j; | ||
} | ||
|
||
private void setArgs(DbSetArgs args) { | ||
this.args = args; | ||
} | ||
|
||
@Override | ||
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { | ||
if (this.args == null || this.args.getArgs()==null){ | ||
return; | ||
} | ||
for (Map.Entry<Integer,String> entry : args.getArgs().entrySet()) { | ||
internalSet(attributes, AttributeKey.stringKey("origin_sql_"+entry.getKey()),entry.getValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onEnd(AttributesBuilder attributes, Context context, REQUEST request, | ||
@Nullable RESPONSE response, @Nullable Throwable error) { | ||
} | ||
} |