Skip to content

Commit a743319

Browse files
committed
minimal manual trace impl
Signed-off-by: Kavindu Dodanduwa <[email protected]>
1 parent e0a7b39 commit a743319

File tree

3 files changed

+250
-145
lines changed

3 files changed

+250
-145
lines changed

providers/flagd/pom.xml

+136-129
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,151 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<parent>
5-
<groupId>dev.openfeature.contrib</groupId>
6-
<artifactId>parent</artifactId>
7-
<version>0.1.0</version>
8-
<relativePath>../../pom.xml</relativePath>
9-
</parent>
10-
<groupId>dev.openfeature.contrib.providers</groupId>
11-
<artifactId>flagd</artifactId>
12-
<version>0.5.8</version> <!--x-release-please-version -->
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>dev.openfeature.contrib</groupId>
7+
<artifactId>parent</artifactId>
8+
<version>0.1.0</version>
9+
<relativePath>../../pom.xml</relativePath>
10+
</parent>
11+
<groupId>dev.openfeature.contrib.providers</groupId>
12+
<artifactId>flagd</artifactId>
13+
<version>0.5.8</version> <!--x-release-please-version -->
1314

14-
<name>flagd</name>
15-
<description>FlagD provider for Java</description>
16-
<url>https://openfeature.dev</url>
15+
<name>flagd</name>
16+
<description>FlagD provider for Java</description>
17+
<url>https://openfeature.dev</url>
1718

18-
<developers>
19-
<developer>
20-
<id>toddbaert</id>
21-
<name>Todd Baert</name>
22-
<organization>OpenFeature</organization>
23-
<url>https://openfeature.dev/</url>
24-
</developer>
25-
</developers>
19+
<developers>
20+
<developer>
21+
<id>toddbaert</id>
22+
<name>Todd Baert</name>
23+
<organization>OpenFeature</organization>
24+
<url>https://openfeature.dev/</url>
25+
</developer>
26+
</developers>
2627

27-
<dependencies>
28-
<!-- we inherent dev.openfeature.javasdk and the test dependencies from the parent pom -->
28+
<dependencies>
29+
<!-- we inherent dev.openfeature.javasdk and the test dependencies from the parent pom -->
2930

30-
<dependency>
31-
<groupId>io.grpc</groupId>
32-
<artifactId>grpc-netty</artifactId>
33-
<version>1.54.1</version>
34-
</dependency>
31+
<dependency>
32+
<groupId>io.grpc</groupId>
33+
<artifactId>grpc-netty</artifactId>
34+
<version>1.54.1</version>
35+
</dependency>
3536

36-
<dependency>
37-
<!-- we only support unix sockets on linux, via epoll native lib -->
38-
<groupId>io.netty</groupId>
39-
<artifactId>netty-transport-native-epoll</artifactId>
40-
<version>4.1.91.Final</version>
41-
<!-- TODO: with 5+ (still alpha), arm is support and we should package multiple versions -->
42-
<classifier>linux-x86_64</classifier>
43-
</dependency>
37+
<dependency>
38+
<!-- we only support unix sockets on linux, via epoll native lib -->
39+
<groupId>io.netty</groupId>
40+
<artifactId>netty-transport-native-epoll</artifactId>
41+
<version>4.1.91.Final</version>
42+
<!-- TODO: with 5+ (still alpha), arm is support and we should package multiple versions -->
43+
<classifier>linux-x86_64</classifier>
44+
</dependency>
4445

45-
<dependency>
46-
<groupId>io.grpc</groupId>
47-
<artifactId>grpc-protobuf</artifactId>
48-
<version>1.54.1</version>
49-
</dependency>
46+
<dependency>
47+
<groupId>io.grpc</groupId>
48+
<artifactId>grpc-protobuf</artifactId>
49+
<version>1.54.1</version>
50+
</dependency>
5051

51-
<dependency>
52-
<groupId>io.grpc</groupId>
53-
<artifactId>grpc-stub</artifactId>
54-
<version>1.54.1</version>
55-
</dependency>
52+
<dependency>
53+
<groupId>io.grpc</groupId>
54+
<artifactId>grpc-stub</artifactId>
55+
<version>1.54.1</version>
56+
</dependency>
5657

57-
<dependency>
58-
<!-- necessary for Java 9+ -->
59-
<groupId>org.apache.tomcat</groupId>
60-
<artifactId>annotations-api</artifactId>
61-
<version>6.0.53</version>
62-
<scope>provided</scope>
63-
</dependency>
58+
<dependency>
59+
<!-- necessary for Java 9+ -->
60+
<groupId>org.apache.tomcat</groupId>
61+
<artifactId>annotations-api</artifactId>
62+
<version>6.0.53</version>
63+
<scope>provided</scope>
64+
</dependency>
6465

65-
<dependency>
66-
<groupId>org.apache.commons</groupId>
67-
<artifactId>commons-collections4</artifactId>
68-
<version>4.4</version>
69-
</dependency>
70-
</dependencies>
66+
<dependency>
67+
<groupId>org.apache.commons</groupId>
68+
<artifactId>commons-collections4</artifactId>
69+
<version>4.4</version>
70+
</dependency>
7171

72-
<build>
73-
<!-- required for protobuf generation -->
74-
<extensions>
75-
<extension>
76-
<groupId>kr.motd.maven</groupId>
77-
<artifactId>os-maven-plugin</artifactId>
78-
<version>1.7.1</version>
79-
</extension>
80-
</extensions>
72+
<dependency>
73+
<groupId>io.opentelemetry</groupId>
74+
<artifactId>opentelemetry-sdk</artifactId>
75+
<version>1.25.0</version>
76+
</dependency>
77+
</dependencies>
8178

82-
<plugins>
83-
<plugin>
84-
<groupId>org.codehaus.mojo</groupId>
85-
<artifactId>exec-maven-plugin</artifactId>
86-
<version>3.1.0</version>
87-
<executions>
88-
<execution>
89-
<id>update-schemas-submodule</id>
90-
<phase>validate</phase>
91-
<goals>
92-
<goal>exec</goal>
93-
</goals>
94-
<configuration>
95-
<!-- run: git submodule update \-\-init \-\-recursive -->
96-
<executable>git</executable>
97-
<arguments>
98-
<argument>submodule</argument>
99-
<argument>update</argument>
100-
<argument>--init</argument>
101-
<argument>--recursive</argument>
102-
</arguments>
103-
</configuration>
104-
</execution>
105-
<execution>
106-
<id>copy-protobuf-definition</id>
107-
<phase>validate</phase>
108-
<goals>
109-
<goal>exec</goal>
110-
</goals>
111-
<configuration>
112-
<!-- run: cp schemas/protobuf/schema/v1/schema.proto src/main/proto/ -->
113-
<executable>cp</executable>
114-
<arguments>
115-
<argument>schemas/protobuf/schema/v1/schema.proto</argument>
116-
<argument>src/main/proto/</argument>
117-
</arguments>
118-
</configuration>
119-
</execution>
120-
</executions>
121-
</plugin>
79+
<build>
80+
<!-- required for protobuf generation -->
81+
<extensions>
82+
<extension>
83+
<groupId>kr.motd.maven</groupId>
84+
<artifactId>os-maven-plugin</artifactId>
85+
<version>1.7.1</version>
86+
</extension>
87+
</extensions>
12288

123-
<plugin>
124-
<groupId>org.xolstice.maven.plugins</groupId>
125-
<artifactId>protobuf-maven-plugin</artifactId>
126-
<version>0.6.1</version>
127-
<configuration>
128-
<protocArtifact>com.google.protobuf:protoc:3.21.1:exe:${os.detected.classifier}</protocArtifact>
129-
<pluginId>grpc-java</pluginId>
130-
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.48.1:exe:${os.detected.classifier}</pluginArtifact>
131-
</configuration>
132-
<executions>
133-
<execution>
134-
<goals>
135-
<goal>compile</goal>
136-
<goal>compile-custom</goal>
137-
</goals>
138-
</execution>
139-
</executions>
140-
</plugin>
141-
</plugins>
142-
</build>
89+
<plugins>
90+
<plugin>
91+
<groupId>org.codehaus.mojo</groupId>
92+
<artifactId>exec-maven-plugin</artifactId>
93+
<version>3.1.0</version>
94+
<executions>
95+
<execution>
96+
<id>update-schemas-submodule</id>
97+
<phase>validate</phase>
98+
<goals>
99+
<goal>exec</goal>
100+
</goals>
101+
<configuration>
102+
<!-- run: git submodule update \-\-init \-\-recursive -->
103+
<executable>git</executable>
104+
<arguments>
105+
<argument>submodule</argument>
106+
<argument>update</argument>
107+
<argument>--init</argument>
108+
<argument>--recursive</argument>
109+
</arguments>
110+
</configuration>
111+
</execution>
112+
<execution>
113+
<id>copy-protobuf-definition</id>
114+
<phase>validate</phase>
115+
<goals>
116+
<goal>exec</goal>
117+
</goals>
118+
<configuration>
119+
<!-- run: cp schemas/protobuf/schema/v1/schema.proto src/main/proto/ -->
120+
<executable>cp</executable>
121+
<arguments>
122+
<argument>schemas/protobuf/schema/v1/schema.proto</argument>
123+
<argument>src/main/proto/</argument>
124+
</arguments>
125+
</configuration>
126+
</execution>
127+
</executions>
128+
</plugin>
129+
130+
<plugin>
131+
<groupId>org.xolstice.maven.plugins</groupId>
132+
<artifactId>protobuf-maven-plugin</artifactId>
133+
<version>0.6.1</version>
134+
<configuration>
135+
<protocArtifact>com.google.protobuf:protoc:3.21.1:exe:${os.detected.classifier}</protocArtifact>
136+
<pluginId>grpc-java</pluginId>
137+
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.48.1:exe:${os.detected.classifier}</pluginArtifact>
138+
</configuration>
139+
<executions>
140+
<execution>
141+
<goals>
142+
<goal>compile</goal>
143+
<goal>compile-custom</goal>
144+
</goals>
145+
</execution>
146+
</executions>
147+
</plugin>
148+
</plugins>
149+
</build>
143150

144151
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package dev.openfeature.contrib.providers.flagd;
2+
3+
import io.grpc.CallOptions;
4+
import io.grpc.Channel;
5+
import io.grpc.ClientCall;
6+
import io.grpc.ClientInterceptor;
7+
import io.grpc.ForwardingClientCall;
8+
import io.grpc.Metadata;
9+
import io.grpc.MethodDescriptor;
10+
import io.opentelemetry.context.Context;
11+
import io.opentelemetry.context.propagation.TextMapSetter;
12+
import io.opentelemetry.sdk.OpenTelemetrySdk;
13+
14+
import javax.annotation.Nullable;
15+
16+
/**
17+
* FlagdGrpcInterceptor is an interceptor for grpc communication from java-sdk to flagd
18+
* <p>
19+
* <a href="https://github.com/open-telemetry/opentelemetry-java-docs">credits</a>
20+
*/
21+
final class FlagdGrpcInterceptor implements ClientInterceptor {
22+
private static final TextMapSetter<Metadata> SETTER = new Setter();
23+
24+
private final OpenTelemetrySdk openTelemetry;
25+
26+
FlagdGrpcInterceptor(final OpenTelemetrySdk openTelemetry) {
27+
this.openTelemetry = openTelemetry;
28+
}
29+
30+
@Override
31+
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
32+
MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions, Channel channel) {
33+
34+
final ClientCall<ReqT, RespT> call = channel.newCall(methodDescriptor, callOptions);
35+
36+
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(call) {
37+
@Override
38+
public void start(Listener<RespT> responseListener, io.grpc.Metadata headers) {
39+
openTelemetry.getPropagators()
40+
.getTextMapPropagator()
41+
.inject(Context.current(), headers, SETTER);
42+
43+
super.start(responseListener, headers);
44+
}
45+
};
46+
}
47+
48+
/**
49+
* Setter implements TextMapSetter with carrier check
50+
*/
51+
static class Setter implements TextMapSetter<Metadata> {
52+
@Override
53+
public void set(@Nullable Metadata carrier, String key, String value) {
54+
if (carrier == null) {
55+
return;
56+
}
57+
58+
carrier.put(io.grpc.Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER), value);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)