Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,19 @@ class GraphQLClient(

/**
* Executes a GraphQL query
* @param queryFileName The .graphql file name
* @param query The GraphQL query string
* @param variables Query variables
* @param dataSerializer Kotlinx serialization serializer for the expected response data type
* @return GraphQLResponse containing either the deserialized data or error information
*/
suspend fun <T> execute(
queryFileName: String,
query: String,
variables: Map<String, JsonElement> = emptyMap(),
dataSerializer: KSerializer<T>,
compress: Boolean = true
): GraphQLResponse<T> = withContext(DispatcherProviderHolder.current.io) {
var connection: HttpURLConnection? = null
val response: GraphQLResponse<T> = try {
val query = loadQuery(queryFileName)
val request = GraphQLRequest(
query = query,
variables = variables
Expand Down Expand Up @@ -143,17 +142,6 @@ class GraphQLClient(
response
}

/**
* Loads GraphQL query from resources
* @param queryFilepath The .graphql file path
* @return Query string
*/
private fun loadQuery(queryFilepath: String): String {
return this::class.java.classLoader?.getResourceAsStream(queryFilepath)?.bufferedReader()?.use {
it.readText()
} ?: throw IllegalStateException("Could not load GraphQL query file: $queryFilepath")
}

private fun gzip(data: ByteArray): ByteArray {
val byteStream = ByteArrayOutputStream()
GZIPOutputStream(byteStream).use { gzipStream ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,61 @@ class SamplingApiService(
) {

companion object {
private const val GET_SAMPLING_CONFIG_QUERY_FILE_PATH = "graphql/GetSamplingConfigQuery.graphql"
private val GET_SAMPLING_CONFIG_QUERY = """
fragment MatchParts on MatchConfig {
regexValue
matchValue
}

query GetSamplingConfig(${'$'}organization_verbose_id: String!) {
sampling(organization_verbose_id: ${'$'}organization_verbose_id) {
spans {
name {
...MatchParts
}
attributes {
key {
...MatchParts
}
attribute {
...MatchParts
}
}
events {
name {
...MatchParts
}
attributes {
key {
...MatchParts
}
attribute {
...MatchParts
}
}
}
samplingRatio
}
logs {
message {
...MatchParts
}
severityText {
...MatchParts
}
attributes {
key {
...MatchParts
}
attribute {
...MatchParts
}
}
samplingRatio
}
}
}
""".trimIndent()
}

/**
Expand All @@ -23,7 +77,7 @@ class SamplingApiService(
try {
val variables = mapOf("organization_verbose_id" to JsonPrimitive(organizationVerboseId))
val response = graphqlClient.execute(
queryFileName = GET_SAMPLING_CONFIG_QUERY_FILE_PATH,
query = GET_SAMPLING_CONFIG_QUERY,
variables = variables,
dataSerializer = SamplingResponse.serializer()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,131 @@ class SessionReplayApiService(
}

companion object {
private const val INITIALIZE_REPLAY_SESSION_QUERY_FILE_PATH = "graphql/InitializeReplaySession.graphql"
private const val IDENTIFY_REPLAY_SESSION_QUERY_FILE_PATH = "graphql/IdentifyReplaySession.graphql"
private const val PUSH_PAYLOAD_QUERY_FILE_PATH = "graphql/PushPayload.graphql"
private val INITIALIZE_REPLAY_SESSION_QUERY = """
fragment MatchParts on MatchConfig {
regexValue
matchValue
}

mutation initializeSession(
${'$'}session_secure_id: String!
${'$'}organization_verbose_id: String!
${'$'}enable_strict_privacy: Boolean!
${'$'}privacy_setting: String!
${'$'}enable_recording_network_contents: Boolean!
${'$'}clientVersion: String!
${'$'}firstloadVersion: String!
${'$'}clientConfig: String!
${'$'}environment: String!
${'$'}id: String!
${'$'}appVersion: String
${'$'}serviceName: String!
${'$'}client_id: String!
${'$'}network_recording_domains: [String!]
) {
initializeSession(
session_secure_id: ${'$'}session_secure_id
organization_verbose_id: ${'$'}organization_verbose_id
enable_strict_privacy: ${'$'}enable_strict_privacy
enable_recording_network_contents: ${'$'}enable_recording_network_contents
clientVersion: ${'$'}clientVersion
firstloadVersion: ${'$'}firstloadVersion
clientConfig: ${'$'}clientConfig
environment: ${'$'}environment
appVersion: ${'$'}appVersion
serviceName: ${'$'}serviceName
fingerprint: ${'$'}id
client_id: ${'$'}client_id
network_recording_domains: ${'$'}network_recording_domains
privacy_setting: ${'$'}privacy_setting
) {
secure_id
project_id
sampling {
spans {
name {
...MatchParts
}
attributes {
key {
...MatchParts
}
attribute {
...MatchParts
}
}
events {
name {
...MatchParts
}
attributes {
key {
...MatchParts
}
attribute {
...MatchParts
}
}
}
samplingRatio
}
logs {
message {
...MatchParts
}
severityText {
...MatchParts
}
attributes {
key {
...MatchParts
}
attribute {
...MatchParts
}
}
samplingRatio
}
}
}
}
""".trimIndent()

private val IDENTIFY_REPLAY_SESSION_QUERY = """
mutation identifySession(
${'$'}session_secure_id: String!
${'$'}user_identifier: String!
${'$'}user_object: Any
) {
identifySession(
session_secure_id: ${'$'}session_secure_id
user_identifier: ${'$'}user_identifier
user_object: ${'$'}user_object
)
}
""".trimIndent()

private val PUSH_PAYLOAD_QUERY = """
mutation PushPayload(
${'$'}session_secure_id: String!
${'$'}payload_id: ID!
${'$'}events: ReplayEventsInput!
${'$'}messages: String!
${'$'}resources: String!
${'$'}web_socket_events: String!
${'$'}errors: [ErrorObjectInput]!
) {
pushPayload(
session_secure_id: ${'$'}session_secure_id
payload_id: ${'$'}payload_id
events: ${'$'}events
messages: ${'$'}messages
resources: ${'$'}resources
web_socket_events: ${'$'}web_socket_events
errors: ${'$'}errors
)
}
""".trimIndent()
}

/**
Expand All @@ -54,7 +176,7 @@ class SessionReplayApiService(
"id" to JsonPrimitive("") // TODO: O11Y-631 - remove hardcoded params
)
val response = graphqlClient.execute(
queryFileName = INITIALIZE_REPLAY_SESSION_QUERY_FILE_PATH,
query = INITIALIZE_REPLAY_SESSION_QUERY,
variables = variables,
dataSerializer = InitializeReplaySessionResponse.serializer()
)
Expand All @@ -78,7 +200,7 @@ class SessionReplayApiService(
"user_object" to userObject
)
val response = graphqlClient.execute(
queryFileName = IDENTIFY_REPLAY_SESSION_QUERY_FILE_PATH,
query = IDENTIFY_REPLAY_SESSION_QUERY,
variables = variables,
dataSerializer = IdentifySessionResponse.serializer()
)
Expand Down Expand Up @@ -124,7 +246,7 @@ class SessionReplayApiService(
)

val response = graphqlClient.execute(
queryFileName = PUSH_PAYLOAD_QUERY_FILE_PATH,
query = PUSH_PAYLOAD_QUERY,
variables = variables,
dataSerializer = PushPayloadResponse.serializer()
)
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading