Skip to content

Commit d2b75be

Browse files
committed
fix(dev): Fix typo in OpenInference environment post processor
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
1 parent 3336516 commit d2b75be

6 files changed

Lines changed: 190 additions & 2 deletions

File tree

arconia-observation/arconia-openinference-semantic-conventions/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies {
2222
optional "org.springframework.ai:spring-ai-client-chat"
2323

2424
testImplementation "org.springframework.boot:spring-boot-starter-test"
25+
testRuntimeOnly project(":arconia-observability:arconia-opentelemetry")
26+
testRuntimeOnly "io.micrometer:micrometer-tracing-bridge-otel"
2527
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
2628

2729
constraints {

arconia-observation/arconia-openinference-semantic-conventions/src/main/java/io/arconia/observation/openinference/autoconfigure/OpenInferenceEnvironmentPropertyAdapters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class OpenInferenceEnvironmentPropertyAdapters {
2121
*/
2222
static PropertyAdapter traces(ConfigurableEnvironment environment) {
2323
Assert.notNull(environment, "environment cannot be null");
24-
String prefix = OpenInferenceProperties.CONFIG_PREFIX + ".traces";
24+
String prefix = OpenInferenceProperties.CONFIG_PREFIX + ".options";
2525
return PropertyAdapter.builder(environment)
2626
.mapBoolean("OPENINFERENCE_HIDE_CHOICES", prefix + ".hide-choices")
2727
.mapBoolean("OPENINFERENCE_HIDE_LLM_INVOCATION_PARAMETERS", prefix + ".hide-llm-invocation-parameters")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Environment Post Processors
22
org.springframework.boot.EnvironmentPostProcessor=\
3-
io.arconia.openinference.observation.autoconfigure.ai.OpenInferenceEnvironmentPostProcessor
3+
io.arconia.observation.openinference.autoconfigure.OpenInferenceEnvironmentPostProcessor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package io.arconia.observation.openinference.autoconfigure;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
import org.springframework.boot.SpringApplication;
9+
import org.springframework.boot.WebApplicationType;
10+
import org.springframework.context.ConfigurableApplicationContext;
11+
import org.springframework.core.env.ConfigurableEnvironment;
12+
import org.springframework.core.env.MapPropertySource;
13+
import org.springframework.core.env.StandardEnvironment;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
17+
/**
18+
* Integration tests for {@link OpenInferenceEnvironmentPostProcessor}.
19+
*/
20+
class OpenInferenceEnvironmentPostProcessorIT {
21+
22+
private static final String PREFIX = OpenInferenceProperties.CONFIG_PREFIX + ".options";
23+
24+
private SpringApplication application;
25+
26+
@BeforeEach
27+
void setup() {
28+
this.application = new SpringApplication(Config.class);
29+
this.application.setWebApplicationType(WebApplicationType.NONE);
30+
}
31+
32+
@Test
33+
void runWhenHasOpenInferencePropertiesInSystemPropertiesShouldConvertToArconiaProperties() {
34+
System.setProperty("OPENINFERENCE_HIDE_INPUTS", "true");
35+
System.setProperty("OPENINFERENCE_HIDE_OUTPUTS", "true");
36+
System.setProperty("OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH", "64000");
37+
38+
try {
39+
ConfigurableApplicationContext context = this.application.run();
40+
41+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-inputs")).isEqualTo("true");
42+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-outputs")).isEqualTo("true");
43+
assertThat(context.getEnvironment().getProperty(PREFIX + ".base64-image-max-length")).isEqualTo("64000");
44+
}
45+
finally {
46+
System.clearProperty("OPENINFERENCE_HIDE_INPUTS");
47+
System.clearProperty("OPENINFERENCE_HIDE_OUTPUTS");
48+
System.clearProperty("OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH");
49+
}
50+
}
51+
52+
@Test
53+
void runWhenHasOpenInferencePropertiesInEnvironmentVariablesShouldConvertToArconiaProperties() {
54+
ConfigurableEnvironment environment = new StandardEnvironment();
55+
Map<String, Object> envVars = new HashMap<>();
56+
envVars.put("OPENINFERENCE_HIDE_INPUTS", "true");
57+
envVars.put("OPENINFERENCE_HIDE_OUTPUTS", "true");
58+
envVars.put("OPENINFERENCE_HIDE_INPUT_MESSAGES", "true");
59+
envVars.put("OPENINFERENCE_HIDE_OUTPUT_MESSAGES", "true");
60+
envVars.put("OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH", "64000");
61+
environment.getPropertySources()
62+
.addFirst(new MapPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, envVars));
63+
this.application.setEnvironment(environment);
64+
65+
ConfigurableApplicationContext context = this.application.run();
66+
67+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-inputs")).isEqualTo("true");
68+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-outputs")).isEqualTo("true");
69+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-input-messages")).isEqualTo("true");
70+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-output-messages")).isEqualTo("true");
71+
assertThat(context.getEnvironment().getProperty(PREFIX + ".base64-image-max-length")).isEqualTo("64000");
72+
}
73+
74+
@Test
75+
void runWhenHasOpenInferencePropertiesInCommandLineArgumentsShouldConvertToArconiaProperties() {
76+
ConfigurableApplicationContext context = this.application.run(
77+
"--OPENINFERENCE_HIDE_INPUTS=true",
78+
"--OPENINFERENCE_HIDE_OUTPUTS=true",
79+
"--OPENINFERENCE_HIDE_CHOICES=true",
80+
"--OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH=64000"
81+
);
82+
83+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-inputs")).isEqualTo("true");
84+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-outputs")).isEqualTo("true");
85+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-choices")).isEqualTo("true");
86+
assertThat(context.getEnvironment().getProperty(PREFIX + ".base64-image-max-length")).isEqualTo("64000");
87+
}
88+
89+
@Test
90+
void runWhenHasOpenInferencePropertiesInApplicationPropertiesShouldConvertToArconiaProperties() {
91+
ConfigurableApplicationContext context = this.application.run(
92+
"--spring.config.location=classpath:application-openinference.properties"
93+
);
94+
95+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-inputs")).isEqualTo("true");
96+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-outputs")).isEqualTo("true");
97+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-input-messages")).isEqualTo("true");
98+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-output-messages")).isEqualTo("true");
99+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-input-images")).isEqualTo("true");
100+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-input-text")).isEqualTo("true");
101+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-output-text")).isEqualTo("true");
102+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-prompts")).isEqualTo("true");
103+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-choices")).isEqualTo("true");
104+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-llm-invocation-parameters")).isEqualTo("true");
105+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-embeddings-text")).isEqualTo("true");
106+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-embeddings-vectors")).isEqualTo("true");
107+
assertThat(context.getEnvironment().getProperty(PREFIX + ".base64-image-max-length")).isEqualTo("64000");
108+
}
109+
110+
@Test
111+
void runWhenHasOpenInferencePropertiesInApplicationYamlShouldConvertToArconiaProperties() {
112+
ConfigurableApplicationContext context = this.application.run(
113+
"--spring.config.location=classpath:application-openinference.yml"
114+
);
115+
116+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-inputs")).isEqualTo("true");
117+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-outputs")).isEqualTo("true");
118+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-input-messages")).isEqualTo("true");
119+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-output-messages")).isEqualTo("true");
120+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-input-images")).isEqualTo("true");
121+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-input-text")).isEqualTo("true");
122+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-output-text")).isEqualTo("true");
123+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-prompts")).isEqualTo("true");
124+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-choices")).isEqualTo("true");
125+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-llm-invocation-parameters")).isEqualTo("true");
126+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-embeddings-text")).isEqualTo("true");
127+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-embeddings-vectors")).isEqualTo("true");
128+
assertThat(context.getEnvironment().getProperty(PREFIX + ".base64-image-max-length")).isEqualTo("64000");
129+
}
130+
131+
@Test
132+
void runWhenHasNoOpenInferencePropertiesShouldNotSetArconiaProperties() {
133+
ConfigurableApplicationContext context = this.application.run();
134+
135+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-inputs")).isNull();
136+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-outputs")).isNull();
137+
assertThat(context.getEnvironment().getProperty(PREFIX + ".base64-image-max-length")).isNull();
138+
}
139+
140+
@Test
141+
void runWhenHasInvalidIntegerPropertyShouldNotConvertIt() {
142+
ConfigurableEnvironment environment = new StandardEnvironment();
143+
Map<String, Object> envVars = new HashMap<>();
144+
envVars.put("OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH", "not-a-number");
145+
envVars.put("OPENINFERENCE_HIDE_INPUTS", "true");
146+
environment.getPropertySources()
147+
.addFirst(new MapPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, envVars));
148+
this.application.setEnvironment(environment);
149+
150+
ConfigurableApplicationContext context = this.application.run();
151+
152+
assertThat(context.getEnvironment().getProperty(PREFIX + ".base64-image-max-length")).isNull();
153+
assertThat(context.getEnvironment().getProperty(PREFIX + ".hide-inputs")).isEqualTo("true");
154+
}
155+
156+
static class Config {
157+
158+
}
159+
160+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
OPENINFERENCE_HIDE_INPUTS=true
2+
OPENINFERENCE_HIDE_OUTPUTS=true
3+
OPENINFERENCE_HIDE_INPUT_MESSAGES=true
4+
OPENINFERENCE_HIDE_OUTPUT_MESSAGES=true
5+
OPENINFERENCE_HIDE_INPUT_IMAGES=true
6+
OPENINFERENCE_HIDE_INPUT_TEXT=true
7+
OPENINFERENCE_HIDE_OUTPUT_TEXT=true
8+
OPENINFERENCE_HIDE_PROMPTS=true
9+
OPENINFERENCE_HIDE_CHOICES=true
10+
OPENINFERENCE_HIDE_LLM_INVOCATION_PARAMETERS=true
11+
OPENINFERENCE_HIDE_EMBEDDINGS_TEXT=true
12+
OPENINFERENCE_HIDE_EMBEDDINGS_VECTORS=true
13+
OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH=64000
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
OPENINFERENCE_HIDE_INPUTS: true
2+
OPENINFERENCE_HIDE_OUTPUTS: true
3+
OPENINFERENCE_HIDE_INPUT_MESSAGES: true
4+
OPENINFERENCE_HIDE_OUTPUT_MESSAGES: true
5+
OPENINFERENCE_HIDE_INPUT_IMAGES: true
6+
OPENINFERENCE_HIDE_INPUT_TEXT: true
7+
OPENINFERENCE_HIDE_OUTPUT_TEXT: true
8+
OPENINFERENCE_HIDE_PROMPTS: true
9+
OPENINFERENCE_HIDE_CHOICES: true
10+
OPENINFERENCE_HIDE_LLM_INVOCATION_PARAMETERS: true
11+
OPENINFERENCE_HIDE_EMBEDDINGS_TEXT: true
12+
OPENINFERENCE_HIDE_EMBEDDINGS_VECTORS: true
13+
OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH: 64000

0 commit comments

Comments
 (0)