@Override public void run() { tclient.trackEvent(name, properties, metrics); } };
/** * Sends a custom event record to Application Insights. Appears in "custom events" in Analytics, Search and Metrics Explorer. * @param name A name for the event. Max length 150. */ public void trackEvent(String name) { trackEvent(name, null, null); }
/** * Sends the specified state of a user session to Application Insights using {@link #trackEvent(String name)} as this method will be deprecated. * @param sessionState {@link com.microsoft.applicationinsights.telemetry.SessionState} * value indicating the state of a user session. * @deprecated This method will be deprecated in version 2.0.0 of the Java SDK. */ @Deprecated public void trackSessionState(SessionState sessionState) { this.trackEvent("Track Session State: " + sessionState.toString()); }
public static boolean sendEvent(TelemetryEventType type, String value, Log logger){ final Map<String, String> properties = new HashMap<String, String>(); properties.put("Description", value); try { client.trackEvent(type.getValue(), properties, null); client.flush(); Thread.sleep(1500); } catch (InterruptedException e) { logger.error(String.format("Failed sending telemetry event of type %s", type.getValue())); } return true; } }
protected void sendEventInternal(final String name, final Map<String, String> properties) { final String eventName = String.format(ACTION_NAME_FORMAT, name); final PropertyMapBuilder builder = new PropertyMapBuilder(properties); // Log that the event occurred (this log is used in testing) logger.debug(String.format("sendEvent(%s, %s)", name, builder.toString())); if (telemetryClient != null) { telemetryClient.trackEvent(eventName, builder.build(), null); } }
private void sendEvent() { this.collector.getProperties().forEach((m) -> { log.info("Sending telemetry event with properties {}", m); this.client.trackEvent(collector.getName(), m, null); this.client.flush(); }); } }
private void sendEvent() { this.collector.getProperties().forEach((m) -> { log.info("Sending telemetry event with properties {}", m); this.client.trackEvent(collector.getName(), m, null); this.client.flush(); }); } }
public void trackEvent(@NonNull String eventName) { this.client.trackEvent(eventName, this.properties, null); this.client.flush(); }
public void trackEvent(@NonNull String eventName) { this.client.trackEvent(eventName, this.properties, null); this.client.flush(); }
public void trackEvent(final String eventName, final Map<String, String> customProperties, final boolean overrideDefaultProperties) { if (!isEnabled) { return; } final Map<String, String> properties = mergeProperties(getDefaultProperties(), customProperties, overrideDefaultProperties); client.trackEvent(eventName, properties, null); client.flush(); }
public void trackEvent(final String eventName, final Map<String, String> customProperties, final boolean overrideDefaultProperties) { if (!isEnabled) { return; } final Map<String, String> properties = mergeProperties(getDefaultProperties(), customProperties, overrideDefaultProperties); client.trackEvent(eventName, properties, null); client.flush(); }
public void trackEvent(final String eventName, final Map<String, String> customProperties, final boolean overrideDefaultProperties) { Map<String, String> properties = getDefaultProperties(); if (this.isAllowTelemetry) { properties = mergeProperties(getDefaultProperties(), customProperties, overrideDefaultProperties); } try { client.trackEvent(eventName, properties, null); client.flush(); } catch (Exception e) { LOGGER.trace("Failed to track event.", e); } }
public void trackEvent(final String eventName, final Map<String, String> customProperties, final boolean overrideDefaultProperties) { Map<String, String> properties = getDefaultProperties(); if (this.isAllowTelemetry) { properties = mergeProperties(getDefaultProperties(), customProperties, overrideDefaultProperties); } try { client.trackEvent(eventName, properties, null); client.flush(); } catch (Exception e) { LOGGER.trace("Failed to track event.", e); } }
public void trackEvent(@NonNull String eventName) { if (isTelemetryAllowed()) { getClient().trackEvent(eventName, getDefaultProperties(), null); getClient().flush(); } }
@Test public void testTrackEventWithName() { client.trackEvent("Event"); verifyAndGetLastEventSent(); }
@Test public void testTrackEventWithEventTelemetry() { EventTelemetry eventTelemetry = new EventTelemetry("Event"); client.trackEvent(eventTelemetry); verifyAndGetLastEventSent(); }
@Test public void testTrackEventWithPropertiesAndMetrics() { Map<String, String> properties = new HashMap<String, String>() {{ put("key", "value"); }}; Map<String, Double> metrics = new HashMap<String, Double>() {{ put("key", 1d); }}; client.trackEvent("Event", properties, metrics); EventTelemetry telemetry = (EventTelemetry) verifyAndGetLastEventSent(); Assert.assertTrue("Expected telemetry property not found", telemetry.getProperties().get("key").equalsIgnoreCase("value")); Assert.assertTrue("Expected telemetry property not found", 1d == telemetry.getMetrics().get("key")); }
@Test public void testNodeNameSent() { client.trackEvent("Event"); EventTelemetry telemetry = (EventTelemetry) verifyAndGetLastEventSent(); String nodeName = telemetry.getContext().getInternal().getNodeName(); Assert.assertFalse(nodeName == null || nodeName.length()==0); }
@Test public void shouldReloadInstrumentationKeyOnTelemetryClient() { TelemetryClient myClient = new TelemetryClient(); EventTelemetry eventTelemetry1 = new EventTelemetry("test1"); myClient.trackEvent(eventTelemetry1); assertThat(eventTelemetry1.getTimestamp()).isNull(); EnvironmentTestUtils.addEnvironment(context, "azure.application-insights.instrumentation-key: 00000000-0000-0000-0000-000000000000"); context.register(PropertyPlaceholderAutoConfiguration.class, ApplicationInsightsTelemetryAutoConfiguration.class); context.refresh(); EventTelemetry eventTelemetry2 = new EventTelemetry("test2"); myClient.trackEvent(eventTelemetry2); assertThat(eventTelemetry2.getTimestamp()).describedAs("Expecting telemetry event to be sent").isNotNull(); }
@Test public void testOverideNodeName(){ String overrideNode = "NewNodeName"; client.getContext().getInternal().setNodeName(overrideNode); client.trackEvent("Event"); EventTelemetry telemetry = (EventTelemetry) verifyAndGetLastEventSent(); String nodeName = telemetry.getContext().getInternal().getNodeName(); Assert.assertTrue("NodeName was not overriden", nodeName.equals(overrideNode)); }