Skip to content
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

Switch to CS2.0 core library #2

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions Core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
29 changes: 18 additions & 11 deletions Core/Core.iml
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":Core" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AppInsights Java" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":core" />
</configuration>
</facet>
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="Gradle: org.apache.commons:commons-lang3:3.3.2" level="project" />
<orderEntry type="library" exported="" name="Gradle: org.apache.httpcomponents:httpclient:4.3.5" level="project" />
<orderEntry type="library" exported="" name="Gradle: org.apache.httpcomponents:httpcore:4.3.2" level="project" />
<orderEntry type="library" exported="" name="Gradle: commons-logging:commons-logging:1.1.3" level="project" />
<orderEntry type="library" exported="" name="Gradle: commons-codec:commons-codec:1.6" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: junit:junit:4.11" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-3.8.2" level="project" />
</component>
</module>
</module>

2 changes: 0 additions & 2 deletions Core/META-INF/MANIFEST.MF

This file was deleted.

12 changes: 4 additions & 8 deletions Core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@

apply plugin: 'java'

jar {
version = '1.0'
baseName = 'appinsights-core'
}
sourceCompatibility = '1.6'
targetCompatibility = '1.6'

repositories {
mavenCentral()
}

dependencies {
compile('org.apache.commons:commons-lang3:3.3.2')
compile('org.apache.httpcomponents:httpclient:4.3.5')
testCompile group: 'junit', name: 'junit', version: '4.11'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile group: 'junit', name: 'junit', version: '3.+'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package com.microsoft.applicationinsights;

import com.microsoft.applicationinsights.channel.TelemetryChannel;
import com.microsoft.applicationinsights.channel.ITelemetryContext;
import com.microsoft.applicationinsights.channel.contracts.DataPoint;
import com.microsoft.applicationinsights.channel.contracts.DataPointType;
import com.microsoft.applicationinsights.channel.contracts.EventData;
import com.microsoft.applicationinsights.channel.contracts.ExceptionData;
import com.microsoft.applicationinsights.channel.contracts.MessageData;
import com.microsoft.applicationinsights.channel.contracts.MetricData;
import com.microsoft.applicationinsights.channel.contracts.shared.ITelemetry;

import java.util.ArrayList;
import java.util.HashMap;

/**
* The public API for recording application insights telemetry.
* Users would call TelemetryClient.track*
*/
public class CoreTelemetryClient {

/**
* The configuration for this telemetry client.
*/
public final CoreTelemetryClientConfig config;

/**
* The telemetry telemetryContext object.
*/
protected ITelemetryContext telemetryContext;

/**
* The telemetry channel for this client.
*/
protected TelemetryChannel channel;

/**
* Force inheritance via a protected constructor
*/
public CoreTelemetryClient(CoreTelemetryClientConfig config) {
this.config = config;
}

/**
* track the event by name.
*
* @param eventName
*/
public void trackEvent(String eventName) {
trackEvent(eventName, null, null);
}

/**
* track the event by name.
*
* @param eventName
*/
public void trackEvent(String eventName, HashMap<String, String> properties) {
trackEvent(eventName, properties, null);
}

/**
* Track the event by event name and customized properties and metrics.
*
* @param eventName event name
* @param properties customized properties
* @param metrics customized metrics
*/
public void trackEvent(String eventName,
HashMap<String, String> properties,
HashMap<String, Double> metrics) {
String localEventName = eventName;
EventData telemetry = new EventData();
telemetry.setName(localEventName);
telemetry.setProperties(properties);
telemetry.setMeasurements(metrics);

track(telemetry, EventData.EnvelopeName, EventData.BaseType);
}

/**
* track with the message.
*
* @param message message for transmission to Application insight
*/
public void trackTrace(String message) {
trackTrace(message, null);
}

/**
* track with the message and properties.
*
* @param message message for transmission to Application insight
* @param properties properties of the message
*/
public void trackTrace(String message, HashMap<String, String> properties) {
MessageData telemetry = new MessageData();
telemetry.setMessage(message);
telemetry.setProperties(properties);

track(telemetry, MessageData.EnvelopeName, MessageData.BaseType);
}

/**
* track the metric.
*
* @param name name of the metric
* @param value value of the metric
*/
public void trackMetric(String name, Double value) {
this.trackMetric(name, value, null);
}

/**
* Track the metric with properties.
*
* @param name metric name
* @param value metric value
* @param properties metric properties
*/
public void trackMetric(String name, double value, HashMap<String, String> properties) {
MetricData telemetry = new MetricData();
telemetry.setProperties(properties);

// todo: batch in client
DataPoint data = new DataPoint();
data.setCount(1);
data.setKind(DataPointType.Measurement);
data.setMax(value);
data.setMax(value);
data.setName(name);
data.setValue(value);
ArrayList<DataPoint> list = new ArrayList<DataPoint>();
list.add(data);
telemetry.setMetrics(list);

track(telemetry, MetricData.EnvelopeName, MetricData.BaseType);
}

/**
* Track exception with properties.
*
* @param exception exception data object
*/
public void trackException(ExceptionData exception) {
this.trackException(exception, null);
}

/**
* Track exception with properties.
*
* @param exception exception data object
* @param properties exception properties
*/
public void trackException(ExceptionData exception, HashMap<String, String> properties) {
ExceptionData localException = exception;
if (localException == null) {
localException = new ExceptionData();
}

exception.setProperties(properties);

track(localException, ExceptionData.EnvelopeName, ExceptionData.BaseType);
}

/**
* send message to the recorder.
*
* @param telemetry telemetry object
* @param itemDataType data type
* @param itemType item type
*/
protected void track(ITelemetry telemetry, String itemDataType, String itemType) {
this.channel.send(this.telemetryContext, telemetry, itemDataType, itemType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.microsoft.applicationinsights;

import com.microsoft.applicationinsights.channel.IChannelConfig;
import com.microsoft.applicationinsights.channel.IContextConfig;
import com.microsoft.applicationinsights.channel.Sender;
import com.microsoft.applicationinsights.channel.SenderConfig;

/**
* Configuration object when instantiating TelemetryClient
*/
public class CoreTelemetryClientConfig implements IChannelConfig, IContextConfig {

/**
* The instrumentation key for this telemetryContext
*/
protected final String instrumentationKey;

/**
* The account id for this telemetryContext
*/
private String accountId;

/**
* The number of milliseconds which must expire before a session is renewed.
*/
private int sessionRenewalMs;

/**
* The number of milliseconds until a session expires.
*/
private int sessionExpirationMs;

/**
* The instrumentation key for this telemetryContext
*/
public String getInstrumentationKey() {
return this.instrumentationKey;
}

/**
* The account id for this telemetryContext
*/
public String getAccountId() {
return accountId;
}

/**
* The number of milliseconds which must expire before a session is renewed.
*/
public int getSessionRenewalMs() {
return sessionRenewalMs;
}

/**
* The number of milliseconds until a session expires.
*/
public int getSessionExpirationMs() {
return sessionExpirationMs;
}

/**
* @return The sender instance for this channel
*/
public SenderConfig getSenderConfig() {
return Sender.instance.getConfig();
}

/**
* Constructs a new instance of the TelemetryClientConfig
* @param iKey The instrumentation key
*/
public CoreTelemetryClientConfig(String iKey){
this(iKey, null);
}

/**
* Constructs a new instance of the TelemetryClientConfig
* @param iKey The instrumentation key
* @param accountId The account ID
*/
public CoreTelemetryClientConfig(String iKey, String accountId){
this.accountId = accountId;
this.instrumentationKey = iKey;
this.sessionExpirationMs = IContextConfig.defaultSessionExpirationMs;
this.sessionRenewalMs = IContextConfig.defaultSessionRenewalMs;
}
}
Loading