38
38
import io .opentelemetry .sdk .trace .data .SpanData ;
39
39
import io .opentelemetry .sdk .trace .export .SimpleSpanProcessor ;
40
40
import io .opentelemetry .sdk .trace .export .SpanExporter ;
41
- import io .opentelemetry .semconv .resource .attributes .ResourceAttributes ;
42
- import io .opentelemetry .semconv .trace .attributes .SemanticAttributes ;
43
41
import org .junit .jupiter .api .AfterAll ;
44
42
import org .junit .jupiter .api .Assertions ;
45
43
import org .junit .jupiter .api .BeforeAll ;
57
55
import java .util .concurrent .TimeUnit ;
58
56
import java .util .concurrent .TimeoutException ;
59
57
58
+ import static io .opentelemetry .semconv .ServiceAttributes .SERVICE_NAME ;
59
+
60
60
public class OpenTelemetryForElasticsearchTest {
61
61
private static final String INDEX = "test-index" ;
62
62
private static final String DOC_ID = "1234567" ;
@@ -100,7 +100,9 @@ public class OpenTelemetryForElasticsearchTest {
100
100
" ]\n " +
101
101
" }\n " +
102
102
"}" ;
103
- public static final String DB_OPERATION = "db.operation" ;
103
+ public static final String DB_SYSTEM = "db.system.name" ;
104
+ public static final String DB_OPERATION = "db.operation.name" ;
105
+ public static final String DB_QUERY = "db.query.text" ;
104
106
public static final String URL_FULL = "url.full" ;
105
107
public static final String SERVER_ADDRESS = "server.address" ;
106
108
public static final String SERVER_PORT = "server.port" ;
@@ -162,7 +164,7 @@ private static void setupHttpServer() throws IOException {
162
164
163
165
private static void setupOTel () {
164
166
Resource resource = Resource .getDefault ()
165
- .merge (Resource .create (Attributes .of (ResourceAttributes . SERVICE_NAME , "es-api-test" )));
167
+ .merge (Resource .create (Attributes .of (SERVICE_NAME , "es-api-test" )));
166
168
167
169
spanExporter = new MockSpanExporter ();
168
170
@@ -189,7 +191,7 @@ public void testGetRequest() throws IOException, InterruptedException {
189
191
Assertions .assertEquals ("get" , span .getName ());
190
192
Assertions .assertEquals ("get" , span .getAttributes ().get (AttributeKey .stringKey (DB_OPERATION )));
191
193
Assertions .assertEquals ("GET" , span .getAttributes ().get (AttributeKey .stringKey (HTTP_REQUEST_METHOD )));
192
- Assertions .assertEquals ("elasticsearch" , span .getAttributes ().get (SemanticAttributes . DB_SYSTEM ));
194
+ Assertions .assertEquals ("elasticsearch" , span .getAttributes ().get (AttributeKey . stringKey ( DB_SYSTEM ) ));
193
195
194
196
String url = "http://" + httpServer .getAddress ().getHostString () + ":" + httpServer .getAddress ().getPort () +
195
197
"/" + INDEX + "/_doc/" + DOC_ID + "?refresh=true" ;
@@ -214,7 +216,7 @@ public void testSearchRequest() throws IOException, InterruptedException {
214
216
Assertions .assertEquals (spanExporter .getSpans ().size (), 1 );
215
217
SpanData span = spanExporter .getSpans ().get (0 );
216
218
Assertions .assertEquals ("search" , span .getName ());
217
- Assertions .assertEquals (queryAsString , span .getAttributes ().get (SemanticAttributes . DB_STATEMENT ));
219
+ Assertions .assertEquals (queryAsString , span .getAttributes ().get (AttributeKey . stringKey ( DB_QUERY ) ));
218
220
}
219
221
220
222
@ Test
@@ -228,7 +230,7 @@ public void testAsyncSearchRequest() throws IOException, InterruptedException, T
228
230
Assertions .assertEquals ("search" , span .getName ());
229
231
230
232
// We're not capturing bodies by default
231
- Assertions .assertNull (span .getAttributes ().get (SemanticAttributes . DB_STATEMENT ));
233
+ Assertions .assertNull (span .getAttributes ().get (AttributeKey . stringKey ( DB_QUERY ) ));
232
234
}
233
235
234
236
private static class MockSpanExporter implements SpanExporter {
0 commit comments