Java Code Examples for org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan#setOperationName()
The following examples show how to use
org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan#setOperationName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override protected void onConstruct(EnhancedInstance enhancedInstance, Object[] objects, AbstractSpan span) { if (objects != null && objects.length == 1) { String rpc = (String) objects[0]; if (span != null && span.isExit()) { /* * The Rpc Annotation is created both in client side and server side, in server side, this * annotation is created only in finagle versions below 17.12.0. * * If the span is not null, which means we are in the client side, we just set op name to the * exitspan. * * If the span is null, which means we are in the server side with finagle version below 17.12.0. * In server side, we don't need this annotation, because we can get op name from Contexts.broadcast * which comes from client. */ span.setOperationName(rpc); tryInjectContext(span); } } }
Example 2
Source File: TracingContext.java From skywalking with Apache License 2.0 | 5 votes |
/** * Create an entry span * * @param operationName most likely a service name * @return span instance. Ref to {@link EntrySpan} */ @Override public AbstractSpan createEntrySpan(final String operationName) { if (isLimitMechanismWorking()) { NoopSpan span = new NoopSpan(); return push(span); } AbstractSpan entrySpan; TracingContext owner = this; final AbstractSpan parentSpan = peek(); final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId(); if (parentSpan != null && parentSpan.isEntry()) { /* * Only add the profiling recheck on creating entry span, * as the operation name could be overrided. */ profilingRecheck(parentSpan, operationName); parentSpan.setOperationName(operationName); entrySpan = parentSpan; return entrySpan.start(); } else { entrySpan = new EntrySpan( spanIdGenerator++, parentSpanId, operationName, owner ); entrySpan.start(); return push(entrySpan); } }
Example 3
Source File: SpanSetOperationNameInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { AbstractSpan tracingSpan = (AbstractSpan) objInst.getSkyWalkingDynamicField(); if (tracingSpan != null) { tracingSpan.setOperationName(allArguments[0].toString()); } return ret; }
Example 4
Source File: SpanSetTagInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { AbstractSpan activeSpan = ContextManager.activeSpan(); String tagKey = String.valueOf(allArguments[0]); String tagValue = String.valueOf(allArguments[1]); if (Tags.PEER_SERVICE.getKey().equals(tagKey)) { activeSpan.setOperationName(tagValue); } else if (Tags.ERROR.getKey().equals(tagKey) && "true".equals(tagValue)) { activeSpan.errorOccurred(); } else { activeSpan.tag(org.apache.skywalking.apm.agent.core.context.tag.Tags.ofKey(tagKey), tagValue); } return ret; }
Example 5
Source File: ActiveSpanSetOperationNameInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(final Class clazz, final Method method, final Object[] allArguments, final Class<?>[] parameterTypes, final MethodInterceptResult result) { try { AbstractSpan activeSpan = ContextManager.activeSpan(); activeSpan.setOperationName(String.valueOf(allArguments[0])); } catch (NullPointerException ignored) { } }
Example 6
Source File: ContextManagerTest.java From skywalking with Apache License 2.0 | 4 votes |
@Test public void createMultipleEntrySpan() { ContextCarrier contextCarrier = new ContextCarrier().deserialize( "1-My40LjU=-MS4yLjM=-4-c2VydmljZQ==-aW5zdGFuY2U=-L2FwcA==-MTI3LjAuMC4xOjgwODA=", ContextCarrier.HeaderVersion.v3 ); assertTrue(contextCarrier.isValid()); AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", contextCarrier); firstEntrySpan.setComponent(ComponentsDefine.TOMCAT); Tags.HTTP.METHOD.set(firstEntrySpan, "GET"); Tags.URL.set(firstEntrySpan, "127.0.0.1:8080"); SpanLayer.asHttp(firstEntrySpan); AbstractSpan secondEntrySpan = ContextManager.createEntrySpan("/testSecondEntry", contextCarrier); secondEntrySpan.setComponent(ComponentsDefine.DUBBO); Tags.URL.set(firstEntrySpan, "dubbo://127.0.0.1:8080"); SpanLayer.asRPCFramework(secondEntrySpan); ContextCarrier injectContextCarrier = new ContextCarrier(); AbstractSpan exitSpan = ContextManager.createExitSpan("/textExitSpan", injectContextCarrier, "127.0.0.1:12800"); exitSpan.errorOccurred(); exitSpan.log(new RuntimeException("exception")); exitSpan.setComponent(ComponentsDefine.HTTPCLIENT); ContextManager.stopSpan(); ContextManager.stopSpan(); SpanLayer.asHttp(firstEntrySpan); firstEntrySpan.setOperationName("/testFirstEntry-setOperationName"); ContextManager.stopSpan(); assertThat(tracingData.getTraceSegments().size(), is(1)); TraceSegment actualSegment = tracingData.getTraceSegments().get(0); assertThat(actualSegment.getRefs().size(), is(1)); TraceSegmentRef ref = actualSegment.getRefs().get(0); MatcherAssert.assertThat(TraceSegmentRefHelper.getPeerHost(ref), is("127.0.0.1:8080")); List<AbstractTracingSpan> spanList = SegmentHelper.getSpan(actualSegment); assertThat(spanList.size(), is(2)); AbstractTracingSpan actualEntrySpan = spanList.get(1); assertThat(actualEntrySpan.getOperationName(), is("/testSecondEntry")); assertThat(actualEntrySpan.getSpanId(), is(0)); assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1)); assertThat(SpanHelper.getComponentId(actualEntrySpan), is(ComponentsDefine.DUBBO.getId())); assertThat(SpanHelper.getLayer(actualEntrySpan), is(SpanLayer.RPC_FRAMEWORK)); AbstractTracingSpan actualExitSpan = spanList.get(0); assertThat(actualExitSpan.getOperationName(), is("/textExitSpan")); assertThat(actualExitSpan.getSpanId(), is(1)); assertThat(AbstractTracingSpanHelper.getParentSpanId(actualExitSpan), is(0)); List<LogDataEntity> logs = AbstractTracingSpanHelper.getLogs(actualExitSpan); assertThat(logs.size(), is(1)); assertThat(logs.get(0).getLogs().size(), is(4)); assertThat(injectContextCarrier.getSpanId(), is(1)); assertThat(injectContextCarrier.getAddressUsedAtClient(), is("127.0.0.1:12800")); }
Example 7
Source File: ContextManagerTest.java From skywalking with Apache License 2.0 | 4 votes |
@Test public void createMultipleExitSpan() { AbstractSpan entrySpan = ContextManager.createEntrySpan("/testEntrySpan", null); entrySpan.setComponent(ComponentsDefine.TOMCAT); Tags.HTTP.METHOD.set(entrySpan, "GET"); Tags.URL.set(entrySpan, "127.0.0.1:8080"); SpanLayer.asHttp(entrySpan); ContextCarrier firstExitSpanContextCarrier = new ContextCarrier(); AbstractSpan firstExitSpan = ContextManager.createExitSpan( "/testFirstExit", firstExitSpanContextCarrier, "127.0.0.1:8080"); firstExitSpan.setComponent(ComponentsDefine.DUBBO); Tags.URL.set(firstExitSpan, "dubbo://127.0.0.1:8080"); SpanLayer.asRPCFramework(firstExitSpan); ContextCarrier secondExitSpanContextCarrier = new ContextCarrier(); AbstractSpan secondExitSpan = ContextManager.createExitSpan( "/testSecondExit", secondExitSpanContextCarrier, "127.0.0.1:9080"); secondExitSpan.setComponent(ComponentsDefine.TOMCAT); Tags.HTTP.METHOD.set(secondExitSpan, "GET"); Tags.URL.set(secondExitSpan, "127.0.0.1:8080"); SpanLayer.asHttp(secondExitSpan); secondExitSpan.setOperationName("/testSecondExit-setOperationName"); ContextManager.stopSpan(); ContextManager.stopSpan(); ContextManager.stopSpan(); assertThat(tracingData.getTraceSegments().size(), is(1)); TraceSegment actualSegment = tracingData.getTraceSegments().get(0); assertNull(actualSegment.getRefs()); List<AbstractTracingSpan> spanList = SegmentHelper.getSpan(actualSegment); assertThat(Objects.requireNonNull(spanList).size(), is(2)); AbstractTracingSpan actualFirstExitSpan = spanList.get(0); assertThat(actualFirstExitSpan.getOperationName(), is("/testFirstExit")); assertThat(actualFirstExitSpan.getSpanId(), is(1)); assertThat(AbstractTracingSpanHelper.getParentSpanId(actualFirstExitSpan), is(0)); assertThat(SpanHelper.getComponentId(actualFirstExitSpan), is(ComponentsDefine.DUBBO.getId())); assertThat(SpanHelper.getLayer(actualFirstExitSpan), is(SpanLayer.RPC_FRAMEWORK)); AbstractTracingSpan actualEntrySpan = spanList.get(1); assertThat(actualEntrySpan.getOperationName(), is("/testEntrySpan")); assertThat(actualEntrySpan.getSpanId(), is(0)); assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1)); assertThat(firstExitSpanContextCarrier.getAddressUsedAtClient(), is("127.0.0.1:8080")); assertThat(firstExitSpanContextCarrier.getSpanId(), is(1)); assertThat(secondExitSpanContextCarrier.getSpanId(), is(1)); }