Skip to content

Commit

Permalink
Updated test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlauer1 committed Jul 2, 2024
1 parent 6d77bfd commit 7047eee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 53 deletions.
2 changes: 1 addition & 1 deletion api/src/OpenTelemetry/Internal/Logging/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import OpenTelemetry.Common (Timestamp, TraceFlags)
import OpenTelemetry.Context.Types (Context)
import OpenTelemetry.Internal.Common.Types (InstrumentationLibrary)
import OpenTelemetry.Internal.Trace.Id (SpanId, TraceId)
import OpenTelemetry.LogAttributes (AnyValue, AttributeLimits, LogAttributes)
import OpenTelemetry.LogAttributes
import OpenTelemetry.Resource (MaterializedResources)


Expand Down
77 changes: 25 additions & 52 deletions api/test/OpenTelemetry/Logging/CoreSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,44 @@ import Test.Hspec

spec :: Spec
spec = describe "Core" $ do
describe "getGlobalLoggerProvider" $ do
describe "The global logger provider" $ do
it "Returns a no-op LoggerProvider when not initialized" $ do
LoggerProvider {..} <- getGlobalLoggerProvider
loggerProviderResource `shouldBe` emptyMaterializedResources
loggerProviderAttributeLimits `shouldBe` LA.defaultAttributeLimits
describe "setGlobalLoggerProvider" $ do
it "works" $ do
lp <-
createLoggerProvider $
LoggerProviderOptions
{ loggerProviderOptionsResource =
materializeResources $
toResource
OperatingSystem
{ osType = "exampleOs"
, osDescription = Nothing
, osName = Nothing
, osVersion = Nothing
it "Allows a LoggerProvider to be set and returns that with subsequent calls to getGlobalLoggerProvider" $ do
let lp =
createLoggerProvider $
LoggerProviderOptions
{ loggerProviderOptionsResource =
materializeResources $
toResource
OperatingSystem
{ osType = "exampleOs"
, osDescription = Nothing
, osName = Nothing
, osVersion = Nothing
}
, loggerProviderOptionsAttributeLimits =
LA.AttributeLimits
{ attributeCountLimit = Just 50
, attributeLengthLimit = Just 50
}
, loggerProviderOptionsAttributeLimits =
LA.AttributeLimits
{ attributeCountLimit = Just 50
, attributeLengthLimit = Just 50
}
}
}

setGlobalLoggerProvider lp

glp <- getGlobalLoggerProvider
glp `shouldBe` lp
describe "addAttribute" $ do
it "works" $ do
lp <- getGlobalLoggerProvider
let l = makeLogger lp InstrumentationLibrary {libraryName = "exampleLibrary", libraryVersion = "", librarySchemaUrl = "", libraryAttributes = A.emptyAttributes}
lr <-
emitLogRecord
l
LogRecordArguments
{ timestamp = Nothing
, observedTimestamp = Nothing
, context = Nothing
, severityText = Nothing
, severityNumber = Nothing
, body = Nothing
, attributes =
H.fromList
[ ("something", "a thing")
]
}
lr <- emitLogRecord l $ (emptyLogRecordArguments ()) {attributes = H.fromList [("something", "a thing")]}

addAttribute lr "anotherThing" ("another thing" :: LA.AnyValue)

(_, attrs) <- LA.getAttributes <$> logRecordGetAttributes lr

attrs
`shouldBe` H.fromList
[ ("anotherThing", "another thing")
Expand All @@ -76,29 +63,15 @@ spec = describe "Core" $ do
it "works" $ do
lp <- getGlobalLoggerProvider
let l = makeLogger lp InstrumentationLibrary {libraryName = "exampleLibrary", libraryVersion = "", librarySchemaUrl = "", libraryAttributes = A.emptyAttributes}
lr <-
emitLogRecord
l
LogRecordArguments
{ timestamp = Nothing
, observedTimestamp = Nothing
, context = Nothing
, severityText = Nothing
, severityNumber = Nothing
, body = Nothing
, attributes =
H.fromList
[ ("something", "a thing")
]
}
lr <- emitLogRecord l $ (emptyLogRecordArguments ()) {attributes = H.fromList [("something", "a thing")]}

addAttributes lr $
H.fromList
[ ("anotherThing", "another thing" :: LA.AnyValue)
, ("twoThing", "the second another thing")
]

(_, attrs) <- LA.getAttributes <$> logRecordGetAttributes lr

attrs
`shouldBe` H.fromList
[ ("anotherThing", "another thing")
Expand Down

0 comments on commit 7047eee

Please sign in to comment.