Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Adds storage component for Application Insights (AppInsights)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenbarli committed Jun 5, 2017
1 parent de546ef commit e304bcd
Show file tree
Hide file tree
Showing 18 changed files with 1,417 additions and 4 deletions.
5 changes: 4 additions & 1 deletion autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
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">
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -33,6 +35,7 @@

<modules>
<module>collector-eventhub</module>
<module>storage-applicationinsights</module>
</modules>
<dependencyManagement>
<dependencies>
Expand Down
84 changes: 84 additions & 0 deletions autoconfigure/storage-applicationinsights/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017 The OpenZipkin Authors
Licensed 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>io.zipkin.azure</groupId>
<version>0.1.6-SNAPSHOT</version>
<artifactId>zipkin-autoconfigure-parent</artifactId>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>zipkin-autoconfigure-storage-applicationinsights</artifactId>
<name>Zipkin Auto Configuration: Azure Application Insights Storage</name>

<properties>
<main.basedir>${project.basedir}/../..</main.basedir>
</properties>

<dependencies>
<dependency>
<groupId>io.zipkin.azure</groupId>
<artifactId>zipkin-storage-applicationinsights</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!--<version>3.8.1</version>-->
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<!--<dependency>-->
<!--<groupId>io.zipkin.brave</groupId>-->
<!--<artifactId>brave-core</artifactId>-->
<!--<version>${brave.version}</version>-->
<!--<optional>true</optional>-->
<!--</dependency>-->
</dependencies>
<!--to do: got to check build contents - got it from autoconfigure-collector-eventhub-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<layout>MODULE</layout>
<classifier>module</classifier>
<!-- https://github.com/spring-projects/spring-boot/issues/3426 transitive exclude doesn't work -->
<excludeGroupIds>
io.zipkin.java,org.springframework.boot,org.springframework,commons-codec,com.fasterxml.jackson.core,com.fasterxml.jackson.dataformat,org.apache.httpcomponents,commons-logging,joda-time,software.amazon.ion
</excludeGroupIds>
<!-- already packaged in zipkin-server -->
<excludeArtifactIds>jmespath-java</excludeArtifactIds>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright 2017 The OpenZipkin Authors
*
* Licensed 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 zipkin.autoconfigure.storage.applicationinsights;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import zipkin.storage.StorageComponent;
import zipkin.storage.applicationinsights.ApplicationInsightsStorage;
import java.util.concurrent.Executor;

/**
* This storage accepts ApplicationInsights logs in a specified category. Each log entry is expected
* to contain a single span, which is TBinaryProtocol big-endian, then base64 encoded. Decoded spans
* are stored asynchronously.
*/
@Configuration
@EnableConfigurationProperties(ZipkinApplicationInsightsStorageProperties.class)
@ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "applicationinsights")
@ConditionalOnMissingBean(StorageComponent.class)
public class ZipkinApplicationInsightsStorageAutoConfiguration {

@Bean @ConditionalOnMissingBean(Executor.class) Executor executor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("ZipkinApplicationInsightsStorage-");
executor.initialize();
return executor;
}

@Bean StorageComponent storage(Executor executor,
ZipkinApplicationInsightsStorageProperties properties,
@Value("${zipkin.storage.strict-trace-id:true}") boolean strictTraceId) {
return ApplicationInsightsStorage.builder()
.strictTraceId(strictTraceId)
.instrumentationKey(properties.getInstrumentationKey())
.applicationId(properties.getApplicationId())
.apikey(properties.getApiKey())
.executor(executor)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2017 The OpenZipkin Authors
*
* Licensed 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 zipkin.autoconfigure.storage.applicationinsights;

import java.util.concurrent.TimeUnit;
import org.springframework.boot.context.properties.ConfigurationProperties;
import zipkin.storage.applicationinsights.ApplicationInsightsStorage;

@ConfigurationProperties("zipkin.storage.applicationinsights")
public class ZipkinApplicationInsightsStorageProperties {

private String instrumentationKey;
private String applicationId;
private String apiKey;

public String getInstrumentationKey() {
return instrumentationKey;
}

public void setInstrumentationKey(String key) {
this.instrumentationKey = key;
}

public String getApplicationId() {
return applicationId;
}

public void setApplicationId(String key) {
this.applicationId = key;
}

public String getApiKey() {
return apiKey;
}

public void setApiKey(String key) {
this.apiKey = key;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
zipkin.autoconfigure.storage.applicationinsights.ZipkinApplicationInsightsStorageAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# When enabled, this allows shorter env properties (ex -Dspring.profiles.active=applicationinsights)
zipkin:
storage:
applicationinsights:
instrumentationKey: ${AI_INSTRUMENTATION_KEY:}
applicationId: ${AI_APPLICATION_ID:}
apiKey: ${AI_API_KEY:}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Copyright 2017 The OpenZipkin Authors
*
* Licensed 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 zipkin.storage.applicationinsights;

import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import zipkin.autoconfigure.storage.applicationinsights.ZipkinApplicationInsightsStorageAutoConfiguration;
import zipkin.autoconfigure.storage.applicationinsights.ZipkinApplicationInsightsStorageProperties;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment;

public class ZipkinApplicationInsightsStorageAutoConfigurationTest {
@Rule
public ExpectedException thrown = ExpectedException.none();

AnnotationConfigApplicationContext context;

@After
public void close() {
if (context != null) {
context.close();
}
}

@Test
public void doesntProvidesStorageComponent_whenStorageTypeNotApplicationInsights() {
context = new AnnotationConfigApplicationContext();
addEnvironment(context, "zipkin.storage.type:elasticsearch");
context.register(PropertyPlaceholderAutoConfiguration.class,
ZipkinApplicationInsightsStorageAutoConfiguration.class);
context.refresh();

thrown.expect(NoSuchBeanDefinitionException.class);
context.getBean(ApplicationInsightsStorage.class);
}

@Test
public void providesStorageComponent_whenStorageTypeApplicationInsights() {
context = new AnnotationConfigApplicationContext();
addEnvironment(context, "zipkin.storage.type:applicationinsights");
context.register(PropertyPlaceholderAutoConfiguration.class,
ZipkinApplicationInsightsStorageAutoConfiguration.class);
context.refresh();

assertThat(context.getBean(ApplicationInsightsStorage.class)).isNotNull();
}

@Test
public void canOverridesProperty_InstrumentationKey() {
context = new AnnotationConfigApplicationContext();
addEnvironment(context,
"zipkin.storage.type:applicationinsights",
"zipkin.storage.applicationinsights.instrumentationKey:xyz",
"zipkin.storage.applicationinsights.applicationId:abc",
"zipkin.storage.applicationinsights.apiKey:mnm"
);
context.register(PropertyPlaceholderAutoConfiguration.class,
ZipkinApplicationInsightsStorageAutoConfiguration.class);
context.refresh();

assertThat(
context.getBean(ZipkinApplicationInsightsStorageProperties.class).getInstrumentationKey())
.isEqualTo("xyz");
}
}
10 changes: 7 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
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">
<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">
<modelVersion>4.0.0</modelVersion>

<groupId>io.zipkin.azure</groupId>
Expand All @@ -24,6 +26,7 @@

<modules>
<module>collector</module>
<module>storage</module>
<module>autoconfigure</module>
</modules>

Expand All @@ -37,7 +40,7 @@

<main.basedir>${project.basedir}</main.basedir>

<zipkin.version>1.23.2</zipkin.version>
<zipkin.version>1.24.0</zipkin.version>
<zipkin-reporter.version>0.7.0</zipkin-reporter.version>
<spring-boot.version>1.5.3.RELEASE</spring-boot.version>
</properties>
Expand All @@ -63,7 +66,8 @@
<scm>
<url>https://github.com/openzipkin/zipkin-azure</url>
<connection>scm:git:https://github.com/openzipkin/zipkin-azure.git</connection>
<developerConnection>scm:git:https://github.com/openzipkin/zipkin-azure.git</developerConnection>
<developerConnection>scm:git:https://github.com/openzipkin/zipkin-azure.git
</developerConnection>
<tag>HEAD</tag>
</scm>

Expand Down
Loading

0 comments on commit e304bcd

Please sign in to comment.