-
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.
NH-94685: capture stacktrace for span
- Loading branch information
1 parent
7fe6363
commit a91e3ee
Showing
21 changed files
with
309 additions
and
200 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
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
44 changes: 44 additions & 0 deletions
44
...om/shared/src/main/java/com/solarwinds/opentelemetry/extensions/SpanStacktraceFilter.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,44 @@ | ||
/* | ||
* © SolarWinds Worldwide, LLC. All rights reserved. | ||
* | ||
* 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.solarwinds.opentelemetry.extensions; | ||
|
||
import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
|
||
import com.solarwinds.joboe.config.ConfigManager; | ||
import com.solarwinds.joboe.config.ConfigProperty; | ||
import io.opentelemetry.sdk.trace.ReadableSpan; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
|
||
public class SpanStacktraceFilter implements Predicate<ReadableSpan> { | ||
private static final Set<String> filterAttributes = new HashSet<>(); | ||
|
||
static { | ||
filterAttributes.add("db.system"); | ||
Set<String> configuredFilterAttributes = | ||
ConfigManager.getConfigOptional( | ||
ConfigProperty.AGENT_SPAN_STACK_TRACE_FILTERS, filterAttributes); | ||
filterAttributes.addAll(configuredFilterAttributes); | ||
} | ||
|
||
@Override | ||
public boolean test(ReadableSpan readableSpan) { | ||
return filterAttributes.stream() | ||
.anyMatch(attr -> readableSpan.getAttribute(stringKey(attr)) != null); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../shared/src/main/java/com/solarwinds/opentelemetry/extensions/StackTraceFilterParser.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,45 @@ | ||
/* | ||
* © SolarWinds Worldwide, LLC. All rights reserved. | ||
* | ||
* 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.solarwinds.opentelemetry.extensions; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonSyntaxException; | ||
import com.google.gson.reflect.TypeToken; | ||
import com.solarwinds.joboe.config.ConfigParser; | ||
import com.solarwinds.joboe.config.InvalidConfigException; | ||
import java.lang.reflect.Type; | ||
import java.util.Arrays; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public final class StackTraceFilterParser implements ConfigParser<String, Set<String>> { | ||
private static final Gson gson = new GsonBuilder().create(); | ||
|
||
@Override | ||
public Set<String> convert(String input) throws InvalidConfigException { | ||
try { | ||
if (input.startsWith("[")) { | ||
Type type = new TypeToken<Set<String>>() {}.getType(); | ||
return gson.fromJson(input, type); | ||
} | ||
return Arrays.stream(input.split(",")).map(String::trim).collect(Collectors.toSet()); | ||
} catch (JsonSyntaxException e) { | ||
throw new InvalidConfigException(e); | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...hared/src/test/java/com/solarwinds/opentelemetry/extensions/SpanStacktraceFilterTest.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,47 @@ | ||
/* | ||
* © SolarWinds Worldwide, LLC. All rights reserved. | ||
* | ||
* 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.solarwinds.opentelemetry.extensions; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.opentelemetry.sdk.trace.ReadableSpan; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class SpanStacktraceFilterTest { | ||
|
||
@InjectMocks private SpanStacktraceFilter tested; | ||
|
||
@Mock private ReadableSpan readableSpanMock; | ||
|
||
@Test | ||
void returnTrueWhenAttributeHasValue() { | ||
when(readableSpanMock.getAttribute(any())).thenReturn("test-value"); | ||
assertTrue(tested.test(readableSpanMock)); | ||
} | ||
|
||
@Test | ||
void returnFalseWhenAttributeHasNoValue() { | ||
assertFalse(tested.test(readableSpanMock)); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...red/src/test/java/com/solarwinds/opentelemetry/extensions/StackTraceFilterParserTest.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,53 @@ | ||
/* | ||
* © SolarWinds Worldwide, LLC. All rights reserved. | ||
* | ||
* 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.solarwinds.opentelemetry.extensions; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.solarwinds.joboe.config.InvalidConfigException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class StackTraceFilterParserTest { | ||
|
||
@InjectMocks private StackTraceFilterParser tested; | ||
|
||
@Test | ||
void returnListOfStringGivenCommaSeparatedString() throws InvalidConfigException { | ||
String input = "name, status"; | ||
Set<String> expected = new HashSet<>(); | ||
expected.add("name"); | ||
|
||
expected.add("status"); | ||
assertEquals(expected, tested.convert(input)); | ||
} | ||
|
||
@Test | ||
void returnListOfStringGivenJsonList() throws InvalidConfigException { | ||
String input = "[\"name\",\"status\"]"; | ||
Set<String> expected = new HashSet<>(); | ||
expected.add("name"); | ||
|
||
expected.add("status"); | ||
assertEquals(expected, tested.convert(input)); | ||
} | ||
} |
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
38 changes: 0 additions & 38 deletions
38
...ation/jdbc/src/main/java/com/solarwinds/opentelemetry/instrumentation/BackTraceCache.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.