Skip to content

add support for tracing with opentelemetry #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functions-framework-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<groupId>dev.openfunction.functions</groupId>
<artifactId>functions-framework-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,70 +75,24 @@ public interface Context {
*/
String getName();

/**
* getMode returns the operating environment mode of the function.
*
* @return Mode
*/
String getMode();

/**
* GetOut returns the returned value of function.
*
* @return Out
*/
Out getOut();

/**
* getRuntime returns the Runtime.
*
* @return String
*/
String getRuntime();

/**
* getHttpPattern returns the path of the server listening for http function.
*
* @return String
*/
String getHttpPattern();


/**
* getInputs returns the Inputs of function.
*
* @return Inputs
*/
Map<String, Component> getInputs();

/**
* getOutputs returns the Outputs of function.
*
* @return Outputs
*/
Map<String, Component> getOutputs();

/**
* getPodName returns the name of the pod the function is running on.
*
* @return name of pod
*/
String getPodName();

/**
* getPodNamespace returns the namespace of the pod the function is running on.
*
* @return namespace of pod
*/
String getPodNamespace();

/**
* @return pre plugins
*/
Map<String, Plugin> getPrePlugins();

/**
* @return post plugin
*/
Map<String, Plugin> getPostPlugins();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package dev.openfunction.functions;

import java.util.Map;

public interface Plugin {
/**
* name return the name of this plugin.
Expand All @@ -33,7 +35,7 @@ public interface Plugin {

/**
* init will create a new plugin, and execute hook in this calling.
* If you do not want to use a new plugin to execute hook, just return `nil`.
* If you do not want to use a new plugin to execute hook, just return `this`.
*
* @return Plugin
*/
Expand Down Expand Up @@ -63,4 +65,9 @@ public interface Plugin {
* @return Object
*/
Object getField(String fieldName);

Boolean needToTracing();

Map<String, String> tagsAddToTracing();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package dev.openfunction.functions;

import java.nio.ByteBuffer;
import java.util.Map;

public class TopicEvent {
/**
Expand Down Expand Up @@ -60,7 +61,9 @@ public class TopicEvent {
*/
private final String topic;

public TopicEvent(String name, String id, String topic, String specversion, String source, String type, String datacontenttype, ByteBuffer data) {
private final Map<String, String> extensions;

public TopicEvent(String name, String id, String topic, String specversion, String source, String type, String datacontenttype, ByteBuffer data, Map<String, String> extensions) {
this.name = name;
this.id = id;
this.topic = topic;
Expand All @@ -69,6 +72,7 @@ public TopicEvent(String name, String id, String topic, String specversion, Stri
this.type = type;
this.datacontenttype = datacontenttype;
this.data = data;
this.extensions = extensions;
}

public String getName() {
Expand Down Expand Up @@ -102,4 +106,8 @@ public ByteBuffer getData() {
public String getTopic() {
return topic;
}

public Map<String, String> getExtensions() {
return this.extensions;
}
}
92 changes: 79 additions & 13 deletions functions-framework-invoker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>dev.openfunction.functions</groupId>
<artifactId>functions-framework-invoker</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>

<properties>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
Expand All @@ -19,7 +19,7 @@
<junit.jupiter.version>5.3.2</junit.jupiter.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<cloudevents.sdk.version>2.3.0</cloudevents.sdk.version>
<cloudevents.sdk.version>2.4.2</cloudevents.sdk.version>
</properties>

<licenses>
Expand All @@ -44,11 +44,23 @@
</repository>
</repositories>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-bom</artifactId>
<version>1.23.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>dev.openfunction.functions</groupId>
<artifactId>functions-framework-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
Expand All @@ -63,7 +75,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>com.ryanharter.auto.value</groupId>
Expand All @@ -80,50 +92,104 @@
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.9</version>
<version>1.10.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>1.9</version>
<version>1.10.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>11.0.9</version>
<version>11.0.14</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>11.0.9</version>
<version>11.0.14</version>
</dependency>

<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk</artifactId>
<version>1.5.0</version>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk-actors</artifactId>
<version>1.5.0</version>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-http-basic</artifactId>
<version>2.3.0</version>
<version>${cloudevents.sdk.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>3.0.5</version>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.0-alpha6</version>
<version>2.0.5</version>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-api</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-common</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>
<version>1.23.1-alpha</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-jaeger</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-jaeger-proto</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-jaeger-thrift</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<version>1.23.1-alpha</version>
</dependency>

<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.openfunction.invoker;

public interface Callback {
Error execute() throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public class Runner {
private static final String FunctionContext = "FUNC_CONTEXT";
private static final String FunctionTarget = "FUNCTION_TARGET";
private static final String FunctionClasspath = "FUNCTION_CLASSPATH";
private static final String SyncRuntime = "Knative";
private static final String AsyncRuntime = "Async";

public static void main(String[] args) {

Expand All @@ -66,9 +64,9 @@ public static void main(String[] args) {

Runtime runtime;
Class<?>[] functionClasses = loadTargets(target, functionClassLoader);
if (Objects.equals(runtimeContext.getRuntime(), SyncRuntime)) {
if (Objects.equals(runtimeContext.getRuntime(), RuntimeContext.SyncRuntime)) {
runtime = new SynchronizeRuntime(runtimeContext, functionClasses);
} else if (Objects.equals(runtimeContext.getRuntime(), AsyncRuntime)) {
} else if (Objects.equals(runtimeContext.getRuntime(), RuntimeContext.AsyncRuntime)) {
runtime = new AsynchronousRuntime(runtimeContext, functionClasses);
} else {
throw new Exception("Unknown runtime");
Expand Down
Loading