Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Add constants for standard span tags (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
oibe authored and yurishkuro committed Jun 17, 2016
1 parent 54fd113 commit 881f849
Show file tree
Hide file tree
Showing 14 changed files with 372 additions and 4 deletions.
11 changes: 10 additions & 1 deletion opentracing-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.opentracing</groupId>
<artifactId>parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
</parent>

<artifactId>opentracing-api</artifactId>
Expand All @@ -32,4 +32,13 @@
<properties>
<main.basedir>${project.basedir}/..</main.basedir>
</properties>

<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
28 changes: 28 additions & 0 deletions opentracing-api/src/main/java/io/opentracing/tag/AbstractTag.java
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 opentracing-api/src/main/java/io/opentracing/tag/BooleanTag.java
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 opentracing-api/src/main/java/io/opentracing/tag/IntTag.java
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 opentracing-api/src/main/java/io/opentracing/tag/ShortTag.java
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 opentracing-api/src/main/java/io/opentracing/tag/StringTag.java
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 opentracing-api/src/main/java/io/opentracing/tag/Tags.java
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");
}
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 opentracing-api/src/test/java/io/opentracing/tag/IntTagTest.java
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 opentracing-api/src/test/java/io/opentracing/tag/ShortTagTest.java
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);
}
}
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);
}
}
Loading

0 comments on commit 881f849

Please sign in to comment.