-
Notifications
You must be signed in to change notification settings - Fork 45
Add oracle context propagation #2434
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
34 changes: 34 additions & 0 deletions
34
...in/java/com/splunk/opentelemetry/instrumentation/jdbc/oracle/OracleContextPropagator.java
This file contains hidden or 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,34 @@ | ||
| /* | ||
| * Copyright Splunk Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.splunk.opentelemetry.instrumentation.jdbc.oracle; | ||
|
|
||
| import com.splunk.opentelemetry.instrumentation.jdbc.AbstractDbContextPropagator; | ||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public final class OracleContextPropagator extends AbstractDbContextPropagator { | ||
| public static final OracleContextPropagator INSTANCE = new OracleContextPropagator(); | ||
|
|
||
| private OracleContextPropagator() {} | ||
|
|
||
| @Override | ||
| protected void setContext(Connection connection, @Nullable String contextInfo) | ||
| throws SQLException { | ||
| connection.setClientInfo("OCSID.ACTION", contextInfo); | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
...ava/com/splunk/opentelemetry/instrumentation/jdbc/oracle/OracleInstrumentationModule.java
This file contains hidden or 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,54 @@ | ||
| /* | ||
| * Copyright Splunk Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.splunk.opentelemetry.instrumentation.jdbc.oracle; | ||
|
|
||
| import static java.util.Collections.singletonList; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
| import java.util.List; | ||
|
|
||
| @AutoService(InstrumentationModule.class) | ||
| public class OracleInstrumentationModule extends InstrumentationModule { | ||
|
|
||
| public OracleInstrumentationModule() { | ||
| super("splunk-jdbc", "splunk-jdbc-oracle"); | ||
| } | ||
|
|
||
| @Override | ||
| public int order() { | ||
| // run after jdbc instrumentation | ||
| return 2; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean defaultEnabled(ConfigProperties config) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public List<TypeInstrumentation> typeInstrumentations() { | ||
| return singletonList(new OracleStatementInstrumentation()); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isHelperClass(String className) { | ||
| return className.startsWith("com.splunk.opentelemetry.instrumentation"); | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
.../com/splunk/opentelemetry/instrumentation/jdbc/oracle/OracleStatementInstrumentation.java
This file contains hidden or 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,71 @@ | ||
| /* | ||
| * Copyright Splunk Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.splunk.opentelemetry.instrumentation.jdbc.oracle; | ||
|
|
||
| import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
| import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; | ||
| import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments; | ||
|
|
||
| import io.opentelemetry.javaagent.bootstrap.CallDepth; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import java.sql.Statement; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| public class OracleStatementInstrumentation implements TypeInstrumentation { | ||
|
|
||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return namedOneOf( | ||
| "oracle.jdbc.driver.OraclePreparedStatementWrapper", | ||
| "oracle.jdbc.driver.OracleStatementWrapper"); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| isPublic() | ||
| .and( | ||
| nameStartsWith("execute") | ||
| .and(takesNoArguments().or(takesArgument(0, String.class)))), | ||
| this.getClass().getName() + "$SetActionAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class SetActionAdvice { | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void onEnter( | ||
| @Advice.This Statement statement, @Advice.Local("splunkCallDepth") CallDepth callDepth) | ||
| throws Exception { | ||
| callDepth = CallDepth.forClass(OracleContextPropagator.class); | ||
| if (callDepth.getAndIncrement() > 0) { | ||
| return; | ||
| } | ||
|
|
||
| OracleContextPropagator.INSTANCE.propagateContext(statement.getConnection()); | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(suppress = Throwable.class) | ||
| public static void onExit(@Advice.Local("splunkCallDepth") CallDepth callDepth) { | ||
| callDepth.decrementAndGet(); | ||
| } | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
...a/com/splunk/opentelemetry/instrumentation/jdbc/sqlserver/SqlServerContextPropagator.java
This file contains hidden or 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,40 @@ | ||
| /* | ||
| * Copyright Splunk Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.splunk.opentelemetry.instrumentation.jdbc.sqlserver; | ||
|
|
||
| import com.splunk.opentelemetry.instrumentation.jdbc.AbstractDbContextPropagator; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.sql.Connection; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.SQLException; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public final class SqlServerContextPropagator extends AbstractDbContextPropagator { | ||
| public static final SqlServerContextPropagator INSTANCE = new SqlServerContextPropagator(); | ||
|
|
||
| private SqlServerContextPropagator() {} | ||
|
|
||
| @Override | ||
| protected void setContext(Connection connection, @Nullable String contextInfo) | ||
| throws SQLException { | ||
| byte[] contextBytes = | ||
| contextInfo == null ? new byte[0] : contextInfo.getBytes(StandardCharsets.UTF_8); | ||
| PreparedStatement statement = connection.prepareStatement("set context_info ?"); | ||
| statement.setBytes(1, contextBytes); | ||
| statement.executeUpdate(); | ||
| } | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've worked together long enough that you know. 🙃