This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add constants for standard span tags (#30)
According to http://opentracing.io/data-semantics/
- Loading branch information
1 parent
54fd113
commit 881f849
Showing
14 changed files
with
372 additions
and
4 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
28 changes: 28 additions & 0 deletions
28
opentracing-api/src/main/java/io/opentracing/tag/AbstractTag.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,28 @@ | ||
/** | ||
* Copyright 2016 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.tag; | ||
|
||
public abstract class AbstractTag<T> { | ||
protected final String key; | ||
|
||
protected AbstractTag(String tagKey) { | ||
this.key = tagKey; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
abstract void set(io.opentracing.Span span, T tagValue); | ||
} |
25 changes: 25 additions & 0 deletions
25
opentracing-api/src/main/java/io/opentracing/tag/BooleanTag.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,25 @@ | ||
/** | ||
* Copyright 2016 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.tag; | ||
|
||
public class BooleanTag extends AbstractTag<Boolean> { | ||
BooleanTag(String key) { | ||
super(key); | ||
} | ||
|
||
@Override | ||
public void set(io.opentracing.Span span, Boolean tagValue) { | ||
span.setTag(super.key, tagValue); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
opentracing-api/src/main/java/io/opentracing/tag/IntTag.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,25 @@ | ||
/** | ||
* Copyright 2016 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.tag; | ||
|
||
public class IntTag extends AbstractTag<Integer> { | ||
IntTag(String key) { | ||
super(key); | ||
} | ||
|
||
@Override | ||
public void set(io.opentracing.Span span, Integer tagValue) { | ||
span.setTag(super.key, tagValue); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
opentracing-api/src/main/java/io/opentracing/tag/ShortTag.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,25 @@ | ||
/** | ||
* Copyright 2016 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.tag; | ||
|
||
public class ShortTag extends AbstractTag<Short> { | ||
ShortTag(String key) { | ||
super(key); | ||
} | ||
|
||
@Override | ||
public void set(io.opentracing.Span span, Short tagValue) { | ||
span.setTag(super.key, tagValue); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
opentracing-api/src/main/java/io/opentracing/tag/StringTag.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 2016 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.tag; | ||
|
||
public class StringTag extends AbstractTag<String> { | ||
StringTag(String key) { | ||
super(key); | ||
} | ||
|
||
@Override | ||
public void set(io.opentracing.Span span, String tagValue) { | ||
span.setTag(super.key, tagValue); | ||
} | ||
|
||
public void set(io.opentracing.Span span, StringTag tag) { | ||
span.setTag(super.key, tag.key); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
opentracing-api/src/main/java/io/opentracing/tag/Tags.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,91 @@ | ||
/** | ||
* Copyright 2016 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.tag; | ||
|
||
/** | ||
* The following span tags are recommended for instrumentors who are trying to capture more | ||
* semantic information about the spans. Tracers may expose additional features based on these | ||
* standardized data points. Tag names follow a general structure of namespacing. | ||
* | ||
* @see http://opentracing.io/data-semantics/ | ||
*/ | ||
|
||
public final class Tags { | ||
private Tags(){} | ||
|
||
/** | ||
* A constant for setting the span kind to indicate that it represents a server span. | ||
*/ | ||
public static final String SPAN_KIND_SERVER = "server"; | ||
|
||
/** | ||
* A constant for setting the span kind to indicate that it represents a client span. | ||
*/ | ||
public static final String SPAN_KIND_CLIENT = "client"; | ||
|
||
/** | ||
* HTTP_URL records the url of the incoming request. | ||
*/ | ||
public static final StringTag HTTP_URL = new StringTag("http.url"); | ||
|
||
/** | ||
* HTTP_STATUS records the http status code of the response. | ||
*/ | ||
public static final IntTag HTTP_STATUS = new IntTag("http.status_code"); | ||
|
||
/** | ||
* PEER_HOST_IPV4 records IPv4 host address of the peer. | ||
*/ | ||
public static final IntTag PEER_HOST_IPV4 = new IntTag("peer.ipv4"); | ||
|
||
/** | ||
* PEER_HOST_IPV6 records the IPv6 host address of the peer. | ||
*/ | ||
public static final StringTag PEER_HOST_IPV6 = new StringTag("peer.ipv6"); | ||
|
||
/** | ||
* PEER_SERVICE records the service name of the peer. | ||
*/ | ||
public static final StringTag PEER_SERVICE = new StringTag("peer.service"); | ||
|
||
/** | ||
* PEER_HOSTNAME records the host name of the peer. | ||
*/ | ||
public static final StringTag PEER_HOSTNAME = new StringTag("peer.hostname"); | ||
|
||
/** | ||
* PEER_PORT records the port number of the peer. | ||
*/ | ||
public static final ShortTag PEER_PORT = new ShortTag("peer.port"); | ||
|
||
/** | ||
* SAMPLING_PRIORITY determines the priority of sampling this Span. | ||
*/ | ||
public static final ShortTag SAMPLING_PRIORITY = new ShortTag("sampling.priority"); | ||
|
||
/** | ||
* SPAN_KIND hints at the relationship between spans, e.g. client/server. | ||
*/ | ||
public static final StringTag SPAN_KIND = new StringTag("span.kind"); | ||
|
||
/** | ||
* COMPONENT is a low-cardinality identifier of the module, library, or package that is instrumented. | ||
*/ | ||
public static final StringTag COMPONENT = new StringTag("component"); | ||
|
||
/** | ||
* ERROR indicates whether a Span ended in an error state. | ||
*/ | ||
public static final BooleanTag ERROR = new BooleanTag("error"); | ||
} |
34 changes: 34 additions & 0 deletions
34
opentracing-api/src/test/java/io/opentracing/tag/BooleanTagTest.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,34 @@ | ||
/** | ||
* Copyright 2016 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.tag; | ||
|
||
import io.opentracing.Span; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class BooleanTagTest { | ||
@Test | ||
public void testSetBoolean() { | ||
Boolean value = true; | ||
String key = "expected.key"; | ||
Span span = mock(Span.class); | ||
|
||
BooleanTag tag = new BooleanTag(key); | ||
tag.set(span, value); | ||
|
||
verify(span).setTag(key, value); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
opentracing-api/src/test/java/io/opentracing/tag/IntTagTest.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,34 @@ | ||
/** | ||
* Copyright 2016 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.tag; | ||
|
||
import io.opentracing.Span; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class IntTagTest { | ||
@Test | ||
public void testSetInt() { | ||
Integer value = 7; | ||
String key = "expected.key"; | ||
Span span = mock(Span.class); | ||
|
||
IntTag tag = new IntTag(key); | ||
tag.set(span, value); | ||
|
||
verify(span).setTag(key, value); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
opentracing-api/src/test/java/io/opentracing/tag/ShortTagTest.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,33 @@ | ||
/** | ||
* Copyright 2016 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.tag; | ||
|
||
import io.opentracing.Span; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class ShortTagTest { | ||
@Test | ||
public void testSetShort() { | ||
Short value = 4; | ||
String key = "expected.key"; | ||
|
||
Span span = mock(Span.class); | ||
ShortTag tag = new ShortTag(key); | ||
tag.set(span, value); | ||
verify(span).setTag(key, value); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
opentracing-api/src/test/java/io/opentracing/tag/StringTagTest.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,35 @@ | ||
/** | ||
* Copyright 2016 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.tag; | ||
|
||
import io.opentracing.Span; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class StringTagTest { | ||
|
||
@Test | ||
public void testSetString() { | ||
String value = "expected.value"; | ||
String key = "expected.key"; | ||
|
||
Span span = mock(Span.class); | ||
StringTag tag = new StringTag(key); | ||
tag.set(span, value); | ||
|
||
verify(span).setTag(key, value); | ||
} | ||
} |
Oops, something went wrong.