Browse Source
Merge in CORE/base-third from ~ELIJAH/base-third:feature/x to feature/x * commit '05178ffabf3882c0cc4efff2becb0e4e7844e2d8': REPORT-80538 feat: 引入skywalking的sdkfeature/x
Elijah-杨铭锐
2 years ago
14 changed files with 548 additions and 0 deletions
@ -0,0 +1,32 @@
|
||||
<!-- |
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more |
||||
~ contributor license agreements. See the NOTICE file distributed with |
||||
~ this work for additional information regarding copyright ownership. |
||||
~ The ASF licenses this file to You 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. |
||||
~ |
||||
--> |
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<groupId>com.fr.third</groupId> |
||||
<artifactId>step1</artifactId> |
||||
<version>${revision}</version> |
||||
<relativePath>../base-third-project/base-third-step1</relativePath> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>fine-skywalking-toolkit-trace</artifactId> |
||||
<packaging>jar</packaging> |
||||
|
||||
<url>http://maven.apache.org</url> |
||||
</project> |
@ -0,0 +1,49 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
/** |
||||
* provide custom api that set tag for current active span. |
||||
*/ |
||||
public class ActiveSpan { |
||||
/** |
||||
* @param key tag key |
||||
* @param value tag value |
||||
*/ |
||||
public static void tag(String key, String value) { |
||||
} |
||||
|
||||
public static void error() { |
||||
} |
||||
|
||||
public static void error(String errorMsg) { |
||||
} |
||||
|
||||
public static void error(Throwable throwable) { |
||||
} |
||||
|
||||
public static void debug(String debugMsg) { |
||||
} |
||||
|
||||
public static void info(String infoMsg) { |
||||
} |
||||
|
||||
public static void setOperationName(String operationName) { |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
import java.util.concurrent.Callable; |
||||
|
||||
@TraceCrossThread |
||||
public class CallableWrapper<V> implements Callable<V> { |
||||
final Callable<V> callable; |
||||
|
||||
public static <V> CallableWrapper<V> of(Callable<V> r) { |
||||
return new CallableWrapper<>(r); |
||||
} |
||||
|
||||
public CallableWrapper(Callable<V> callable) { |
||||
this.callable = callable; |
||||
} |
||||
|
||||
@Override |
||||
public V call() throws Exception { |
||||
return callable.call(); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
import java.util.function.Consumer; |
||||
|
||||
@TraceCrossThread |
||||
public class ConsumerWrapper<V> implements Consumer<V> { |
||||
final Consumer<V> consumer; |
||||
|
||||
public ConsumerWrapper(Consumer<V> consumer) { |
||||
this.consumer = consumer; |
||||
} |
||||
|
||||
public static <V> ConsumerWrapper<V> of(Consumer<V> consumer) { |
||||
return new ConsumerWrapper(consumer); |
||||
} |
||||
|
||||
@Override |
||||
public void accept(V v) { |
||||
this.consumer.accept(v); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,40 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
import java.util.function.Function; |
||||
|
||||
@TraceCrossThread |
||||
public class FunctionWrapper<T, R> implements Function<T, R> { |
||||
final Function<T, R> function; |
||||
|
||||
public FunctionWrapper(Function<T, R> function) { |
||||
this.function = function; |
||||
} |
||||
|
||||
public static <T, R> FunctionWrapper<T, R> of(Function<T, R> function) { |
||||
return new FunctionWrapper(function); |
||||
} |
||||
|
||||
@Override |
||||
public R apply(T t) { |
||||
return this.function.apply(t); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Inherited; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* After the exception status checker activated in the agent, the span wouldn't be marked as error status if the |
||||
* exception has this annotation. |
||||
*/ |
||||
@Target(ElementType.TYPE) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Inherited |
||||
public @interface IgnoredException { |
||||
} |
@ -0,0 +1,36 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
@TraceCrossThread |
||||
public class RunnableWrapper implements Runnable { |
||||
final Runnable runnable; |
||||
|
||||
public RunnableWrapper(Runnable runnable) { |
||||
this.runnable = runnable; |
||||
} |
||||
|
||||
public static RunnableWrapper of(Runnable r) { |
||||
return new RunnableWrapper(r); |
||||
} |
||||
|
||||
@Override |
||||
public void run() { |
||||
this.runnable.run(); |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
import java.util.function.Supplier; |
||||
|
||||
@TraceCrossThread |
||||
public class SupplierWrapper<V> implements Supplier<V> { |
||||
final Supplier<V> supplier; |
||||
|
||||
public static <V> SupplierWrapper<V> of(Supplier<V> r) { |
||||
return new SupplierWrapper<>(r); |
||||
} |
||||
|
||||
public SupplierWrapper(Supplier<V> supplier) { |
||||
this.supplier = supplier; |
||||
} |
||||
|
||||
@Override |
||||
public V get() { |
||||
return supplier.get(); |
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Repeatable; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* Tag the current active span with key {@link #key()} and value {@link #value()}, if there is no active span, this |
||||
* annotation takes no effect. |
||||
* |
||||
* @see Tags |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Repeatable(Tags.class) |
||||
public @interface Tag { |
||||
/** |
||||
* @return the key of the tag to be injected into the current active span |
||||
*/ |
||||
String key(); |
||||
|
||||
/** |
||||
* @return the value of the tag to be injected into the current active span, in the form of the customized |
||||
* enhancement rules, for more information, refer to https://github.com/apache/skywalking/blob/master/docs/en/setup/service-agent/java-agent/Customize-enhance-trace.md#how-to-configure
|
||||
*/ |
||||
String value(); |
||||
} |
@ -0,0 +1,46 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* A wrapper annotation for {@link Tag} that allows to apply multiple tags to a single method span, |
||||
* |
||||
* <pre> |
||||
* @Tag(key = "tag1", value = "arg[0]") |
||||
* @Tag(key = "tag2", value = "arg[1]") |
||||
* public void test(String param1, String param2) { |
||||
* // ...
|
||||
* } |
||||
* </pre> |
||||
* |
||||
* @see Tag |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
public @interface Tags { |
||||
/** |
||||
* @see Tag |
||||
*/ |
||||
Tag[] value(); |
||||
} |
@ -0,0 +1,38 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* The agent create local span if the method that annotation with {@link Trace}. The value of span operation name will |
||||
* fetch by {@link #operationName()}. if the value of {@link #operationName()} is blank string. the operation name will |
||||
* be set the class name + method name. |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
public @interface Trace { |
||||
/** |
||||
* @return operation name, the default value is blank string. |
||||
*/ |
||||
String operationName() default ""; |
||||
} |
@ -0,0 +1,76 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
/** |
||||
* Try to access the sky-walking tracer context. The context is not existed, always. only the middleware, component, or |
||||
* rpc-framework are supported in the current invoke stack, in the same thread, the context will be available. |
||||
* <p> |
||||
*/ |
||||
public class TraceContext { |
||||
|
||||
/** |
||||
* Try to get the traceId of current trace context. |
||||
* |
||||
* @return traceId, if it exists, or empty {@link String}. |
||||
*/ |
||||
public static String traceId() { |
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* Try to get the segmentId of current trace context. |
||||
* |
||||
* @return segmentId, if it exists, or empty {@link String}. |
||||
*/ |
||||
public static String segmentId() { |
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* Try to get the spanId of current trace context. The spanId is a negative number when the trace context is |
||||
* missing. |
||||
* |
||||
* @return spanId, if it exists, or empty {@link String}. |
||||
*/ |
||||
public static int spanId() { |
||||
return -1; |
||||
} |
||||
|
||||
/** |
||||
* Try to get the custom value from trace context. |
||||
* |
||||
* @return custom data value. |
||||
*/ |
||||
public static Optional<String> getCorrelation(String key) { |
||||
return Optional.empty(); |
||||
} |
||||
|
||||
/** |
||||
* Put the custom key/value into trace context. |
||||
* |
||||
* @return previous value if it exists. |
||||
*/ |
||||
public static Optional<String> putCorrelation(String key, String value) { |
||||
return Optional.empty(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,30 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.toolkit.trace; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
@Target(ElementType.TYPE) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
public @interface TraceCrossThread { |
||||
|
||||
} |
Loading…
Reference in new issue