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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add runtime classes for FileReader/FileWriter instrumentation #1843

Merged
merged 35 commits into from Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f050409
Add runtime classes for FileIOStream instrumentation
romtsn Dec 3, 2021
6f326ba
Add NotNull annotation to StringUtils
romtsn Dec 3, 2021
70e7948
Add NotNull and Nullable annotations
romtsn Dec 3, 2021
301fb6a
Add final modifiers
romtsn Dec 3, 2021
09cfe00
Extract repeating logic
romtsn Dec 3, 2021
49c828c
Exception -> IOException
romtsn Dec 6, 2021
6819c36
Adjust span description and remove todos
romtsn Dec 6, 2021
96d005a
Refine finishSpan
romtsn Dec 6, 2021
36a8e3e
Set throwable for a span
romtsn Dec 6, 2021
067af96
Add test for SentryFIS and adjust logic
romtsn Dec 9, 2021
2270a43
Add test for FIS
romtsn Dec 9, 2021
916a814
Remove unused ctors
romtsn Dec 9, 2021
a617617
Fix SentryFIS counting
romtsn Dec 9, 2021
d3c2fc4
Fix SentryFIS read operation
romtsn Dec 9, 2021
be5aedd
Add Tests for SentryFOS
romtsn Dec 9, 2021
e9491d8
Formatting
romtsn Dec 9, 2021
19c524f
Dump API
romtsn Dec 9, 2021
ab90c1e
Changelog
romtsn Dec 9, 2021
d9e8a74
Set throwable in-place
romtsn Dec 13, 2021
3a4bee3
Pass only isSendDefaultPii instead of IHub
romtsn Dec 13, 2021
5ca25a0
V -> T generic
romtsn Dec 13, 2021
2297464
Change doc of performIO
romtsn Dec 13, 2021
aa8ad65
Make ctors package private
romtsn Dec 13, 2021
c6144c7
SentryFIOS @Open -> final
romtsn Dec 13, 2021
faf315f
Make IHub ctors package-private
romtsn Dec 13, 2021
4b1804f
Improve one-byte read method perf
romtsn Dec 13, 2021
67e4720
Locale.US -> Locale.ROOT
romtsn Dec 13, 2021
34c3c8d
Extract SentryOptions into a variable
romtsn Dec 13, 2021
4f8919e
Split getSut into 2 methods
romtsn Dec 13, 2021
4709983
Spotless
romtsn Dec 13, 2021
f15d3af
Dump api
romtsn Dec 13, 2021
a3b6103
Make SentryFIOS public
romtsn Dec 13, 2021
ff28d76
Add SentryFileReader/SentryFileWriter
romtsn Dec 13, 2021
94b2ba8
Merge branch 'main' into feat/file-reader-writer-instr
romtsn Dec 13, 2021
bf506e5
Changelog
romtsn Dec 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
* Feat: Add locale to device context and deprecate language (#1832)
* Ref: change `java.util.Random` to `java.security.SecureRandom` for possible security reasons (#1831)
* Feat: Add `SentryFileInputStream` and `SentryFileOutputStream` for File I/O performance instrumentation (#1826)
- Feat: Add `SentryFileReader` and `SentryFileWriter` for File I/O instrumentation (#1843)

## 5.4.3

Expand Down
14 changes: 14 additions & 0 deletions sentry/api/sentry.api
Expand Up @@ -1471,6 +1471,20 @@ public final class io/sentry/instrumentation/file/SentryFileOutputStream$Factory
public static fun create (Ljava/io/FileOutputStream;Ljava/lang/String;Z)Ljava/io/FileOutputStream;
}

public final class io/sentry/instrumentation/file/SentryFileReader : java/io/InputStreamReader {
public fun <init> (Ljava/io/File;)V
public fun <init> (Ljava/io/FileDescriptor;)V
public fun <init> (Ljava/lang/String;)V
}

public final class io/sentry/instrumentation/file/SentryFileWriter : java/io/OutputStreamWriter {
public fun <init> (Ljava/io/File;)V
public fun <init> (Ljava/io/File;Z)V
public fun <init> (Ljava/io/FileDescriptor;)V
public fun <init> (Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Z)V
}

public final class io/sentry/protocol/App : io/sentry/IUnknownPropertiesConsumer {
public static final field TYPE Ljava/lang/String;
public fun <init> ()V
Expand Down
@@ -0,0 +1,26 @@
package io.sentry.instrumentation.file;

import io.sentry.IHub;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import org.jetbrains.annotations.NotNull;

public final class SentryFileReader extends InputStreamReader {
public SentryFileReader(final @NotNull String fileName) throws FileNotFoundException {
super(new SentryFileInputStream(fileName));
}

public SentryFileReader(final @NotNull File file) throws FileNotFoundException {
super(new SentryFileInputStream(file));
}

public SentryFileReader(final @NotNull FileDescriptor fd) {
super(new SentryFileInputStream(fd));
}

SentryFileReader(final @NotNull File file, final @NotNull IHub hub) throws FileNotFoundException {
super(new SentryFileInputStream(file, hub));
}
}
@@ -0,0 +1,36 @@
package io.sentry.instrumentation.file;

import io.sentry.IHub;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.OutputStreamWriter;
import org.jetbrains.annotations.NotNull;

public final class SentryFileWriter extends OutputStreamWriter {
public SentryFileWriter(final @NotNull String fileName) throws FileNotFoundException {
super(new SentryFileOutputStream(fileName));
}

public SentryFileWriter(final @NotNull String fileName, final boolean append)
throws FileNotFoundException {
super(new SentryFileOutputStream(fileName, append));
}

public SentryFileWriter(final @NotNull File file) throws FileNotFoundException {
super(new SentryFileOutputStream(file));
}

public SentryFileWriter(final @NotNull File file, final boolean append)
throws FileNotFoundException {
super(new SentryFileOutputStream(file, append));
}

public SentryFileWriter(final @NotNull FileDescriptor fd) {
super(new SentryFileOutputStream(fd));
}

SentryFileWriter(final @NotNull File file, final @NotNull IHub hub) throws FileNotFoundException {
super(new SentryFileOutputStream(file, hub));
}
}
@@ -0,0 +1,56 @@
package io.sentry.instrumentation.file

import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import io.sentry.IHub
import io.sentry.SentryOptions
import io.sentry.SentryTracer
import io.sentry.SpanStatus.OK
import io.sentry.TransactionContext
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
import kotlin.test.assertEquals

class SentryFileReaderTest {
class Fixture {
val hub = mock<IHub>()
val sentryTracer = SentryTracer(TransactionContext("name", "op"), hub)

internal fun getSut(
tmpFile: File,
activeTransaction: Boolean = true,
): SentryFileReader {
tmpFile.writeText("TEXT")
whenever(hub.options).thenReturn(SentryOptions())
if (activeTransaction) {
whenever(hub.span).thenReturn(sentryTracer)
}
return SentryFileReader(tmpFile, hub)
}
}

@get:Rule
val tmpDir = TemporaryFolder()

private val fixture = Fixture()

private val tmpFile: File get() = tmpDir.newFile("test.txt")

@Test
fun `captures a span`() {
val reader = fixture.getSut(tmpFile)
reader.readText()
reader.close()

assertEquals(fixture.sentryTracer.children.size, 1)
val fileIOSpan = fixture.sentryTracer.children.first()
assertEquals(fileIOSpan.spanContext.operation, "file.read")
assertEquals(fileIOSpan.spanContext.description, "test.txt (4 B)")
assertEquals(fileIOSpan.data["file.size"], 4L)
assertEquals(fileIOSpan.throwable, null)
assertEquals(fileIOSpan.isFinished, true)
assertEquals(fileIOSpan.status, OK)
}
}
@@ -0,0 +1,55 @@
package io.sentry.instrumentation.file

import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import io.sentry.IHub
import io.sentry.SentryOptions
import io.sentry.SentryTracer
import io.sentry.SpanStatus.OK
import io.sentry.TransactionContext
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
import kotlin.test.assertEquals

class SentryFileWriterTest {
class Fixture {
val hub = mock<IHub>()
val sentryTracer = SentryTracer(TransactionContext("name", "op"), hub)

internal fun getSut(
tmpFile: File,
activeTransaction: Boolean = true,
): SentryFileWriter {
whenever(hub.options).thenReturn(SentryOptions())
if (activeTransaction) {
whenever(hub.span).thenReturn(sentryTracer)
}
return SentryFileWriter(tmpFile, hub)
}
}

@get:Rule
val tmpDir = TemporaryFolder()

private val fixture = Fixture()

private val tmpFile: File get() = tmpDir.newFile("test.txt")

@Test
fun `captures a span`() {
val writer = fixture.getSut(tmpFile)
writer.write("TEXT")
writer.close()

assertEquals(fixture.sentryTracer.children.size, 1)
val fileIOSpan = fixture.sentryTracer.children.first()
assertEquals(fileIOSpan.spanContext.operation, "file.write")
assertEquals(fileIOSpan.spanContext.description, "test.txt (4 B)")
assertEquals(fileIOSpan.data["file.size"], 4L)
assertEquals(fileIOSpan.throwable, null)
assertEquals(fileIOSpan.isFinished, true)
assertEquals(fileIOSpan.status, OK)
}
}