-
Notifications
You must be signed in to change notification settings - Fork 12
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
Custom Span Name #4
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
43cb5cd
prefixes span names, shows in haystack
f47e244
test not working
0d984f9
added test for commandlistener
194afcc
format changes
46c3a54
Update README.md
avnandu 4b68b69
made fixes
611439b
Merge branch 'span-name' of https://github.com/avnandu/java-mongo-dri…
2e578ad
Merge pull request #1 from avnandu/span-name
avnandu a56d26e
spelling error
avnandu 45991bc
Converted from 1.8 -> 1.7 compatible code
31f2f66
Converted from 1.8 -> 1.7 compatible code
c1821b9
Merge pull request #2 from katholen/review-comments
katholen 1ed2107
Update readme documentation
6dddebb
Update readme documentation
052a851
Add copyright
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
29 changes: 29 additions & 0 deletions
29
src/main/java/io/opentracing/contrib/mongo/MongoSpanNameProvider.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,29 @@ | ||
/* | ||
* Copyright 2017-2018 The OpenTracing Authors | ||
* | ||
* 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 io.opentracing.contrib.mongo; | ||
|
||
import java.util.function.Function; | ||
|
||
public class MongoSpanNameProvider { | ||
|
||
private static final String NO_OPERATION = "unknown"; | ||
|
||
public static Function<String, String> OPERATION_NAME = (operationName) -> ((operationName == null) ? NO_OPERATION : operationName); | ||
|
||
public static Function<String, String> PREFIX_OPERATION_NAME(final String prefix) { | ||
return (operationName) -> | ||
((prefix == null) ? "" : prefix) | ||
+ ((operationName == null) ? NO_OPERATION : operationName); | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/test/java/io/opentracing/contrib/mongo/MongoSpanNameProviderTest.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 @@ | ||
/* | ||
* Copyright 2017-2018 The OpenTracing Authors | ||
* | ||
* 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 io.opentracing.contrib.mongo; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class MongoSpanNameProviderTest { | ||
|
||
Function<String, String> prefixSpanName; | ||
String actual = ""; | ||
|
||
@Before | ||
public void setUp() { | ||
prefixSpanName = MongoSpanNameProvider.PREFIX_OPERATION_NAME("mongo."); | ||
} | ||
|
||
@Test | ||
public void testInsertPrefix() { | ||
actual = prefixSpanName.apply("insert"); | ||
assertEquals("mongo.insert", actual); | ||
} | ||
|
||
@Test | ||
public void testFindPrefix() { | ||
actual = prefixSpanName.apply("find"); | ||
assertEquals("mongo.find", actual); | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/test/java/io/opentracing/contrib/mongo/TracingCommandListenerTest.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,74 @@ | ||
/* | ||
* Copyright 2017-2018 The OpenTracing Authors | ||
* | ||
* 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 io.opentracing.contrib.mongo; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.bson.BsonDocument; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.mongodb.ServerAddress; | ||
import com.mongodb.connection.ClusterId; | ||
import com.mongodb.connection.ConnectionDescription; | ||
import com.mongodb.connection.ServerId; | ||
import com.mongodb.event.CommandStartedEvent; | ||
|
||
import io.opentracing.Span; | ||
import io.opentracing.Tracer; | ||
import io.opentracing.mock.MockSpan; | ||
import io.opentracing.mock.MockTracer; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class TracingCommandListenerTest { | ||
|
||
Tracer tracer = new MockTracer(); | ||
private String prefix = "mongo."; | ||
Function<String, String> prefixSpanName; | ||
Function<String, String> operationName; | ||
TracingCommandListener withProvider; | ||
TracingCommandListener withoutProvider; | ||
CommandStartedEvent event; | ||
Span span; | ||
|
||
@Before | ||
public void setUp() { | ||
operationName = MongoSpanNameProvider.OPERATION_NAME; | ||
prefixSpanName = MongoSpanNameProvider.PREFIX_OPERATION_NAME(prefix); | ||
withProvider = new TracingCommandListener(tracer, prefixSpanName); | ||
withoutProvider = new TracingCommandListener(tracer); | ||
event = new CommandStartedEvent( | ||
1 | ||
, new ConnectionDescription(new ServerId(new ClusterId(), new ServerAddress())) | ||
, "databaseName" | ||
, "commandName" | ||
, new BsonDocument() | ||
); | ||
} | ||
|
||
@Test | ||
public void testDefault() { | ||
span = withoutProvider.buildSpan(event); | ||
MockSpan mockSpan = (MockSpan) span; | ||
assertEquals(mockSpan.operationName(), operationName.apply(event.getCommandName())); | ||
} | ||
|
||
@Test | ||
public void testPrefix() { | ||
span = withProvider.buildSpan(event); | ||
MockSpan mockSpan = (MockSpan) span; | ||
assertEquals(mockSpan.operationName(), prefixSpanName.apply(event.getCommandName())); | ||
} | ||
} |
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.
MongoDriver support java 1.6+
So I think we cannot upgrade java version until MongoDriver will require it.