Skip to content

Commit ea84f0a

Browse files
authored
Merge pull request #10 from wanjunlei/opentelemetry
add support for tracing with opentelemetry
2 parents 8faa503 + 7ccbca3 commit ea84f0a

File tree

24 files changed

+983
-516
lines changed

24 files changed

+983
-516
lines changed

functions-framework-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
<groupId>dev.openfunction.functions</groupId>
3434
<artifactId>functions-framework-api</artifactId>
35-
<version>1.0.0-SNAPSHOT</version>
35+
<version>1.1.0-SNAPSHOT</version>
3636

3737
<properties>
3838
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

functions-framework-api/src/main/java/dev/openfunction/functions/Context.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -75,70 +75,24 @@ public interface Context {
7575
*/
7676
String getName();
7777

78-
/**
79-
* getMode returns the operating environment mode of the function.
80-
*
81-
* @return Mode
82-
*/
83-
String getMode();
84-
8578
/**
8679
* GetOut returns the returned value of function.
8780
*
8881
* @return Out
8982
*/
9083
Out getOut();
9184

92-
/**
93-
* getRuntime returns the Runtime.
94-
*
95-
* @return String
96-
*/
97-
String getRuntime();
98-
9985
/**
10086
* getHttpPattern returns the path of the server listening for http function.
10187
*
10288
* @return String
10389
*/
10490
String getHttpPattern();
10591

106-
107-
/**
108-
* getInputs returns the Inputs of function.
109-
*
110-
* @return Inputs
111-
*/
112-
Map<String, Component> getInputs();
113-
11492
/**
11593
* getOutputs returns the Outputs of function.
11694
*
11795
* @return Outputs
11896
*/
11997
Map<String, Component> getOutputs();
120-
121-
/**
122-
* getPodName returns the name of the pod the function is running on.
123-
*
124-
* @return name of pod
125-
*/
126-
String getPodName();
127-
128-
/**
129-
* getPodNamespace returns the namespace of the pod the function is running on.
130-
*
131-
* @return namespace of pod
132-
*/
133-
String getPodNamespace();
134-
135-
/**
136-
* @return pre plugins
137-
*/
138-
Map<String, Plugin> getPrePlugins();
139-
140-
/**
141-
* @return post plugin
142-
*/
143-
Map<String, Plugin> getPostPlugins();
14498
}

functions-framework-api/src/main/java/dev/openfunction/functions/Plugin.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package dev.openfunction.functions;
1818

19+
import java.util.Map;
20+
1921
public interface Plugin {
2022
/**
2123
* name return the name of this plugin.
@@ -33,7 +35,7 @@ public interface Plugin {
3335

3436
/**
3537
* init will create a new plugin, and execute hook in this calling.
36-
* If you do not want to use a new plugin to execute hook, just return `nil`.
38+
* If you do not want to use a new plugin to execute hook, just return `this`.
3739
*
3840
* @return Plugin
3941
*/
@@ -63,4 +65,9 @@ public interface Plugin {
6365
* @return Object
6466
*/
6567
Object getField(String fieldName);
68+
69+
Boolean needToTracing();
70+
71+
Map<String, String> tagsAddToTracing();
72+
6673
}

functions-framework-api/src/main/java/dev/openfunction/functions/TopicEvent.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package dev.openfunction.functions;
1818

1919
import java.nio.ByteBuffer;
20+
import java.util.Map;
2021

2122
public class TopicEvent {
2223
/**
@@ -60,7 +61,9 @@ public class TopicEvent {
6061
*/
6162
private final String topic;
6263

63-
public TopicEvent(String name, String id, String topic, String specversion, String source, String type, String datacontenttype, ByteBuffer data) {
64+
private final Map<String, String> extensions;
65+
66+
public TopicEvent(String name, String id, String topic, String specversion, String source, String type, String datacontenttype, ByteBuffer data, Map<String, String> extensions) {
6467
this.name = name;
6568
this.id = id;
6669
this.topic = topic;
@@ -69,6 +72,7 @@ public TopicEvent(String name, String id, String topic, String specversion, Stri
6972
this.type = type;
7073
this.datacontenttype = datacontenttype;
7174
this.data = data;
75+
this.extensions = extensions;
7276
}
7377

7478
public String getName() {
@@ -102,4 +106,8 @@ public ByteBuffer getData() {
102106
public String getTopic() {
103107
return topic;
104108
}
109+
110+
public Map<String, String> getExtensions() {
111+
return this.extensions;
112+
}
105113
}

functions-framework-invoker/pom.xml

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<groupId>dev.openfunction.functions</groupId>
1212
<artifactId>functions-framework-invoker</artifactId>
13-
<version>1.0.0-SNAPSHOT</version>
13+
<version>1.1.0-SNAPSHOT</version>
1414

1515
<properties>
1616
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
@@ -19,7 +19,7 @@
1919
<junit.jupiter.version>5.3.2</junit.jupiter.version>
2020
<maven.compiler.source>11</maven.compiler.source>
2121
<maven.compiler.target>11</maven.compiler.target>
22-
<cloudevents.sdk.version>2.3.0</cloudevents.sdk.version>
22+
<cloudevents.sdk.version>2.4.2</cloudevents.sdk.version>
2323
</properties>
2424

2525
<licenses>
@@ -44,11 +44,23 @@
4444
</repository>
4545
</repositories>
4646

47+
<dependencyManagement>
48+
<dependencies>
49+
<dependency>
50+
<groupId>io.opentelemetry</groupId>
51+
<artifactId>opentelemetry-bom</artifactId>
52+
<version>1.23.1</version>
53+
<type>pom</type>
54+
<scope>import</scope>
55+
</dependency>
56+
</dependencies>
57+
</dependencyManagement>
58+
4759
<dependencies>
4860
<dependency>
4961
<groupId>dev.openfunction.functions</groupId>
5062
<artifactId>functions-framework-api</artifactId>
51-
<version>1.0.0-SNAPSHOT</version>
63+
<version>1.1.0-SNAPSHOT</version>
5264
</dependency>
5365
<dependency>
5466
<groupId>io.cloudevents</groupId>
@@ -63,7 +75,7 @@
6375
<dependency>
6476
<groupId>com.google.code.gson</groupId>
6577
<artifactId>gson</artifactId>
66-
<version>2.9.0</version>
78+
<version>2.10.1</version>
6779
</dependency>
6880
<dependency>
6981
<groupId>com.ryanharter.auto.value</groupId>
@@ -80,50 +92,104 @@
8092
<dependency>
8193
<groupId>com.google.auto.value</groupId>
8294
<artifactId>auto-value</artifactId>
83-
<version>1.9</version>
95+
<version>1.10.1</version>
8496
<scope>provided</scope>
8597
</dependency>
8698
<dependency>
8799
<groupId>com.google.auto.value</groupId>
88100
<artifactId>auto-value-annotations</artifactId>
89-
<version>1.9</version>
101+
<version>1.10.1</version>
90102
<scope>provided</scope>
91103
</dependency>
92104
<dependency>
93105
<groupId>org.eclipse.jetty</groupId>
94106
<artifactId>jetty-servlet</artifactId>
95-
<version>11.0.9</version>
107+
<version>11.0.14</version>
96108
</dependency>
97109
<dependency>
98110
<groupId>org.eclipse.jetty</groupId>
99111
<artifactId>jetty-server</artifactId>
100-
<version>11.0.9</version>
112+
<version>11.0.14</version>
101113
</dependency>
102114

103115
<dependency>
104116
<groupId>io.dapr</groupId>
105117
<artifactId>dapr-sdk</artifactId>
106-
<version>1.5.0</version>
118+
<version>1.8.0</version>
107119
</dependency>
108120
<dependency>
109121
<groupId>io.dapr</groupId>
110122
<artifactId>dapr-sdk-actors</artifactId>
111-
<version>1.5.0</version>
123+
<version>1.8.0</version>
112124
</dependency>
113125
<dependency>
114126
<groupId>io.cloudevents</groupId>
115127
<artifactId>cloudevents-http-basic</artifactId>
116-
<version>2.3.0</version>
128+
<version>${cloudevents.sdk.version}</version>
117129
</dependency>
118130
<dependency>
119131
<groupId>org.glassfish.jersey.core</groupId>
120132
<artifactId>jersey-common</artifactId>
121-
<version>3.0.5</version>
133+
<version>3.1.1</version>
122134
</dependency>
123135
<dependency>
124136
<groupId>org.slf4j</groupId>
125137
<artifactId>slf4j-simple</artifactId>
126-
<version>2.0.0-alpha6</version>
138+
<version>2.0.5</version>
139+
</dependency>
140+
141+
<dependency>
142+
<groupId>io.opentelemetry</groupId>
143+
<artifactId>opentelemetry-api</artifactId>
144+
</dependency>
145+
<dependency>
146+
<groupId>io.opentelemetry.instrumentation</groupId>
147+
<artifactId>opentelemetry-instrumentation-api</artifactId>
148+
<version>1.23.0</version>
149+
</dependency>
150+
<dependency>
151+
<groupId>io.opentelemetry</groupId>
152+
<artifactId>opentelemetry-sdk</artifactId>
153+
</dependency>
154+
<dependency>
155+
<groupId>io.opentelemetry</groupId>
156+
<artifactId>opentelemetry-sdk-common</artifactId>
157+
</dependency>
158+
<dependency>
159+
<groupId>io.opentelemetry</groupId>
160+
<artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>
161+
<version>1.23.1-alpha</version>
162+
</dependency>
163+
<dependency>
164+
<groupId>io.opentelemetry</groupId>
165+
<artifactId>opentelemetry-exporter-otlp</artifactId>
166+
</dependency>
167+
<dependency>
168+
<groupId>io.opentelemetry</groupId>
169+
<artifactId>opentelemetry-exporter-zipkin</artifactId>
170+
</dependency>
171+
<dependency>
172+
<groupId>io.opentelemetry</groupId>
173+
<artifactId>opentelemetry-exporter-jaeger</artifactId>
174+
</dependency>
175+
<dependency>
176+
<groupId>io.opentelemetry</groupId>
177+
<artifactId>opentelemetry-exporter-jaeger-proto</artifactId>
178+
</dependency>
179+
<dependency>
180+
<groupId>io.opentelemetry</groupId>
181+
<artifactId>opentelemetry-exporter-jaeger-thrift</artifactId>
182+
</dependency>
183+
<dependency>
184+
<groupId>io.opentelemetry</groupId>
185+
<artifactId>opentelemetry-semconv</artifactId>
186+
<version>1.23.1-alpha</version>
187+
</dependency>
188+
189+
<dependency>
190+
<groupId>commons-beanutils</groupId>
191+
<artifactId>commons-beanutils</artifactId>
192+
<version>1.9.4</version>
127193
</dependency>
128194
</dependencies>
129195

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dev.openfunction.invoker;
2+
3+
public interface Callback {
4+
Error execute() throws Exception;
5+
}

functions-framework-invoker/src/main/java/dev/openfunction/invoker/Runner.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ public class Runner {
4444
private static final String FunctionContext = "FUNC_CONTEXT";
4545
private static final String FunctionTarget = "FUNCTION_TARGET";
4646
private static final String FunctionClasspath = "FUNCTION_CLASSPATH";
47-
private static final String SyncRuntime = "Knative";
48-
private static final String AsyncRuntime = "Async";
4947

5048
public static void main(String[] args) {
5149

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

6765
Runtime runtime;
6866
Class<?>[] functionClasses = loadTargets(target, functionClassLoader);
69-
if (Objects.equals(runtimeContext.getRuntime(), SyncRuntime)) {
67+
if (Objects.equals(runtimeContext.getRuntime(), RuntimeContext.SyncRuntime)) {
7068
runtime = new SynchronizeRuntime(runtimeContext, functionClasses);
71-
} else if (Objects.equals(runtimeContext.getRuntime(), AsyncRuntime)) {
69+
} else if (Objects.equals(runtimeContext.getRuntime(), RuntimeContext.AsyncRuntime)) {
7270
runtime = new AsynchronousRuntime(runtimeContext, functionClasses);
7371
} else {
7472
throw new Exception("Unknown runtime");

0 commit comments

Comments
 (0)