Package net.snowflake.client.jdbc.telemetry

## Class TelemetryClient

- java.lang.Object
- - net.snowflake.client.jdbc.telemetry.TelemetryClient

All Implemented Interfaces:
  `Telemetry`

    public class TelemetryClient
    extends Object
    implements Telemetry

Copyright (c) 2018-2019 Snowflake Computing Inc. All rights reserved.

Telemetry Service Interface

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `addLogToBatch​(com.fasterxml.jackson.databind.node.ObjectNode message, long timeStamp)` Add log to batch to be submitted to telemetry.
`void` `addLogToBatch​(TelemetryData log)` Add log to batch to be submitted to telemetry.
`int` `bufferSize()` For test use only
`void` `close()` Close telemetry connector and send any unsubmitted logs
`static Telemetry` `createSessionlessTelemetry​(org.apache.http.impl.client.CloseableHttpClient httpClient, String serverUrl)` Initialize the sessionless telemetry connector using KEYPAIR_JWT as the default auth type
`static Telemetry` `createSessionlessTelemetry​(org.apache.http.impl.client.CloseableHttpClient httpClient, String serverUrl, String authType)` Initialize the sessionless telemetry connector
`static Telemetry` `createSessionlessTelemetry​(org.apache.http.impl.client.CloseableHttpClient httpClient, String serverUrl, String authType, int flushSize)` Initialize the sessionless telemetry connector
`static Telemetry` `createTelemetry​(Connection conn)` Initialize the telemetry connector
`static Telemetry` `createTelemetry​(Connection conn, int flushSize)` Initialize the telemetry connector
`static Telemetry` `createTelemetry​(SFSession session)` Initialize the telemetry connector
`static Telemetry` `createTelemetry​(SFSession session, int flushSize)` Initialize the telemetry connector
`void` `disableTelemetry()` Disable any use of the client to add/send metrics
`boolean` `isClosed()` Return whether the client has been closed
`boolean` `isTelemetryEnabled()` Return whether the client can be used to add/send metrics
`LinkedList<TelemetryData>` `logBuffer()` For test use only
`void` `postProcess​(String queryId, String sqlState, int vendorCode, Throwable ex)` A hook for post-processing after sending telemetry data.
`void` `refreshToken​(String token)` Refresh the JWT/OAuth token
`Future<Boolean>` `sendBatchAsync()` Send all cached logs to server
`boolean` `sendLog​(com.fasterxml.jackson.databind.node.ObjectNode message, long timeStamp)` Send a log to the server, along with any existing logs waiting to be sent
`boolean` `sendLog​(TelemetryData log)` Send a log to the server, along with any existing logs waiting to be sent

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### isTelemetryEnabled

    public boolean isTelemetryEnabled()

Return whether the client can be used to add/send metrics

Returns:
  whether client is enabled

#### disableTelemetry

    public void disableTelemetry()

Disable any use of the client to add/send metrics

#### createTelemetry

    public static Telemetry createTelemetry​(Connection conn,
                                            int flushSize)

Initialize the telemetry connector

Parameters:
  `conn` - connection with the session to use for the connector
  `flushSize` - maximum size of telemetry batch before flush
Returns:
  a telemetry connector

#### createTelemetry

    public static Telemetry createTelemetry​(Connection conn)

Initialize the telemetry connector

Parameters:
  `conn` - connection with the session to use for the connector
Returns:
  a telemetry connector

#### createTelemetry

    public static Telemetry createTelemetry​(SFSession session)

Initialize the telemetry connector

Parameters:
  `session` - session to use for telemetry dumps
Returns:
  a telemetry connector

#### createTelemetry

    public static Telemetry createTelemetry​(SFSession session,
                                            int flushSize)

Initialize the telemetry connector

Parameters:
  `session` - session to use for telemetry dumps
  `flushSize` - maximum size of telemetry batch before flush
Returns:
  a telemetry connector

#### createSessionlessTelemetry

    public static Telemetry createSessionlessTelemetry​(org.apache.http.impl.client.CloseableHttpClient httpClient,
                                                       String serverUrl)

Initialize the sessionless telemetry connector using KEYPAIR_JWT as the default auth type

Parameters:
  `httpClient` - client object used to communicate with other machine
  `serverUrl` - server url
Returns:
  a telemetry connector

#### createSessionlessTelemetry

    public static Telemetry createSessionlessTelemetry​(org.apache.http.impl.client.CloseableHttpClient httpClient,
                                                       String serverUrl,
                                                       String authType)

Initialize the sessionless telemetry connector

Parameters:
  `httpClient` - client object used to communicate with other machine
  `serverUrl` - server url
  `authType` - authorization type for sessionless telemetry
Returns:
  a telemetry connector

#### createSessionlessTelemetry

    public static Telemetry createSessionlessTelemetry​(org.apache.http.impl.client.CloseableHttpClient httpClient,
                                                       String serverUrl,
                                                       String authType,
                                                       int flushSize)

Initialize the sessionless telemetry connector

Parameters:
  `httpClient` - client object used to communicate with other machine
  `serverUrl` - server url
  `authType` - authorization type for sessionless telemetry
  `flushSize` - maximum size of telemetry batch before flush
Returns:
  a telemetry connector

#### addLogToBatch

    public void addLogToBatch​(TelemetryData log)

Add log to batch to be submitted to telemetry. Send batch if forceFlushSize reached

Specified by:
  `addLogToBatch` in interface `Telemetry`
Parameters:
  `log` - entry to add

#### addLogToBatch

    public void addLogToBatch​(com.fasterxml.jackson.databind.node.ObjectNode message,
                              long timeStamp)

Add log to batch to be submitted to telemetry. Send batch if forceFlushSize reached

Parameters:
  `message` - json node of log
  `timeStamp` - timestamp to use for log

#### close

    public void close()

Close telemetry connector and send any unsubmitted logs

Specified by:
  `close` in interface `Telemetry`

#### isClosed

    public boolean isClosed()

Return whether the client has been closed

Returns:
  whether client is closed

#### sendBatchAsync

    public Future<Boolean> sendBatchAsync()

Description copied from interface: `Telemetry`
Send all cached logs to server

Specified by:
  `sendBatchAsync` in interface `Telemetry`
Returns:
  future indicating whether the logs were sent successfully

#### postProcess

    public void postProcess​(String queryId,
                            String sqlState,
                            int vendorCode,
                            Throwable ex)

Description copied from interface: `Telemetry`
A hook for post-processing after sending telemetry data. Can be used, for example, for additional error handling.

Specified by:
  `postProcess` in interface `Telemetry`
Parameters:
  `queryId` - The query id
  `sqlState` - The SQL state as defined in net.snowflake.common.core.SqlState
  `vendorCode` - The vendor code for localized messages
  `ex` - The throwable that caused this.

#### sendLog

    public boolean sendLog​(TelemetryData log)
                    throws IOException

Send a log to the server, along with any existing logs waiting to be sent

Parameters:
  `log` - entry to send
Returns:
  whether the logs were sent successfully
Throws:
  `IOException` - if closed or uploading batch fails

#### sendLog

    public boolean sendLog​(com.fasterxml.jackson.databind.node.ObjectNode message,
                           long timeStamp)
                    throws IOException

Send a log to the server, along with any existing logs waiting to be sent

Parameters:
  `message` - json node of log
  `timeStamp` - timestamp to use for log
Returns:
  whether the logs were sent successfully
Throws:
  `IOException` - if closed or uploading batch fails

#### bufferSize

    public int bufferSize()

For test use only

Returns:
  the number of cached logs

#### logBuffer

    public LinkedList<TelemetryData> logBuffer()

For test use only

Returns:
  a copy of the logs currently in the buffer

#### refreshToken

    public void refreshToken​(String token)

Refresh the JWT/OAuth token

Parameters:
  `token` - latest JWT/OAuth token